@@ -678,7 +678,7 @@ var used = []
678
678
* Chai version
679
679
*/
680
680
681
- exports . version = '2.2 .0' ;
681
+ exports . version = '2.3 .0' ;
682
682
683
683
/*!
684
684
* Assertion Error
@@ -1051,7 +1051,7 @@ module.exports = function (chai, _) {
1051
1051
* ### .any
1052
1052
*
1053
1053
* Sets the `any` flag, (opposite of the `all` flag)
1054
- * later used in the `keys` assertion.
1054
+ * later used in the `keys` assertion.
1055
1055
*
1056
1056
* expect(foo).to.have.any.keys('bar', 'baz');
1057
1057
*
@@ -1068,7 +1068,7 @@ module.exports = function (chai, _) {
1068
1068
/**
1069
1069
* ### .all
1070
1070
*
1071
- * Sets the `all` flag (opposite of the `any` flag)
1071
+ * Sets the `all` flag (opposite of the `any` flag)
1072
1072
* later used by the `keys` assertion.
1073
1073
*
1074
1074
* expect(foo).to.have.all.keys('bar', 'baz');
@@ -1249,7 +1249,7 @@ module.exports = function (chai, _) {
1249
1249
* Asserts that the target is `null`.
1250
1250
*
1251
1251
* expect(null).to.be.null;
1252
- * expect(undefined).not.to .be.null;
1252
+ * expect(undefined).to.not .be.null;
1253
1253
*
1254
1254
* @name null
1255
1255
* @api public
@@ -1725,7 +1725,7 @@ module.exports = function (chai, _) {
1725
1725
* green: { tea: 'matcha' }
1726
1726
* , teas: [ 'chai', 'matcha', { tea: 'konacha' } ]
1727
1727
* };
1728
- *
1728
+ *
1729
1729
* expect(deepObj).to.have.deep.property('green.tea', 'matcha');
1730
1730
* expect(deepObj).to.have.deep.property('teas[1]', 'matcha');
1731
1731
* expect(deepObj).to.have.deep.property('teas[2].tea', 'konacha');
@@ -1846,6 +1846,55 @@ module.exports = function (chai, _) {
1846
1846
Assertion . addMethod ( 'ownProperty' , assertOwnProperty ) ;
1847
1847
Assertion . addMethod ( 'haveOwnProperty' , assertOwnProperty ) ;
1848
1848
1849
+ /**
1850
+ * ### .ownPropertyDescriptor(name[, descriptor[, message]])
1851
+ *
1852
+ * Asserts that the target has an own property descriptor `name`, that optionally matches `descriptor`.
1853
+ *
1854
+ * expect('test').to.have.ownPropertyDescriptor('length');
1855
+ * expect('test').to.have.ownPropertyDescriptor('length', { enumerable: false, configurable: false, writable: false, value: 4 });
1856
+ * expect('test').not.to.have.ownPropertyDescriptor('length', { enumerable: false, configurable: false, writable: false, value: 3 });
1857
+ * expect('test').ownPropertyDescriptor('length').to.have.property('enumerable', false);
1858
+ * expect('test').ownPropertyDescriptor('length').to.have.keys('value');
1859
+ *
1860
+ * @name ownPropertyDescriptor
1861
+ * @alias haveOwnPropertyDescriptor
1862
+ * @param {String } name
1863
+ * @param {Object } descriptor _optional_
1864
+ * @param {String } message _optional_
1865
+ * @api public
1866
+ */
1867
+
1868
+ function assertOwnPropertyDescriptor ( name , descriptor , msg ) {
1869
+ if ( typeof descriptor === 'string' ) {
1870
+ msg = descriptor ;
1871
+ descriptor = null ;
1872
+ }
1873
+ if ( msg ) flag ( this , 'message' , msg ) ;
1874
+ var obj = flag ( this , 'object' ) ;
1875
+ var actualDescriptor = Object . getOwnPropertyDescriptor ( Object ( obj ) , name ) ;
1876
+ if ( actualDescriptor && descriptor ) {
1877
+ this . assert (
1878
+ _ . eql ( descriptor , actualDescriptor )
1879
+ , 'expected the own property descriptor for ' + _ . inspect ( name ) + ' on #{this} to match ' + _ . inspect ( descriptor ) + ', got ' + _ . inspect ( actualDescriptor )
1880
+ , 'expected the own property descriptor for ' + _ . inspect ( name ) + ' on #{this} to not match ' + _ . inspect ( descriptor )
1881
+ , descriptor
1882
+ , actualDescriptor
1883
+ , true
1884
+ ) ;
1885
+ } else {
1886
+ this . assert (
1887
+ actualDescriptor
1888
+ , 'expected #{this} to have an own property descriptor for ' + _ . inspect ( name )
1889
+ , 'expected #{this} to not have an own property descriptor for ' + _ . inspect ( name )
1890
+ ) ;
1891
+ }
1892
+ flag ( this , 'object' , actualDescriptor ) ;
1893
+ }
1894
+
1895
+ Assertion . addMethod ( 'ownPropertyDescriptor' , assertOwnPropertyDescriptor ) ;
1896
+ Assertion . addMethod ( 'haveOwnPropertyDescriptor' , assertOwnPropertyDescriptor ) ;
1897
+
1849
1898
/**
1850
1899
* ### .length(value)
1851
1900
*
@@ -1947,30 +1996,30 @@ module.exports = function (chai, _) {
1947
1996
* ### .keys(key1, [key2], [...])
1948
1997
*
1949
1998
* Asserts that the target contains any or all of the passed-in keys.
1950
- * Use in combination with `any`, `all`, `contains`, or `have` will affect
1999
+ * Use in combination with `any`, `all`, `contains`, or `have` will affect
1951
2000
* what will pass.
1952
- *
1953
- * When used in conjunction with `any`, at least one key that is passed
1954
- * in must exist in the target object. This is regardless whether or not
2001
+ *
2002
+ * When used in conjunction with `any`, at least one key that is passed
2003
+ * in must exist in the target object. This is regardless whether or not
1955
2004
* the `have` or `contain` qualifiers are used. Note, either `any` or `all`
1956
2005
* should be used in the assertion. If neither are used, the assertion is
1957
2006
* defaulted to `all`.
1958
- *
1959
- * When both `all` and `contain` are used, the target object must have at
2007
+ *
2008
+ * When both `all` and `contain` are used, the target object must have at
1960
2009
* least all of the passed-in keys but may have more keys not listed.
1961
- *
2010
+ *
1962
2011
* When both `all` and `have` are used, the target object must both contain
1963
2012
* all of the passed-in keys AND the number of keys in the target object must
1964
- * match the number of keys passed in (in other words, a target object must
2013
+ * match the number of keys passed in (in other words, a target object must
1965
2014
* have all and only all of the passed-in keys).
1966
- *
2015
+ *
1967
2016
* expect({ foo: 1, bar: 2 }).to.have.any.keys('foo', 'baz');
1968
2017
* expect({ foo: 1, bar: 2 }).to.have.any.keys('foo');
1969
2018
* expect({ foo: 1, bar: 2 }).to.contain.any.keys('bar', 'baz');
1970
2019
* expect({ foo: 1, bar: 2 }).to.contain.any.keys(['foo']);
1971
2020
* expect({ foo: 1, bar: 2 }).to.contain.any.keys({'foo': 6});
1972
2021
* expect({ foo: 1, bar: 2 }).to.have.all.keys(['bar', 'foo']);
1973
- * expect({ foo: 1, bar: 2 }).to.have.all.keys({'bar': 6, 'foo', 7});
2022
+ * expect({ foo: 1, bar: 2 }).to.have.all.keys({'bar': 6, 'foo': 7});
1974
2023
* expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys(['bar', 'foo']);
1975
2024
* expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys([{'bar': 6}}]);
1976
2025
*
0 commit comments