Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write comprehensive tests for .not.property #76

Closed
astorije opened this issue Dec 18, 2016 · 2 comments
Closed

Write comprehensive tests for .not.property #76

astorije opened this issue Dec 18, 2016 · 2 comments
Milestone

Comments

@astorije
Copy link
Owner

Meaning of .not.property changes between Chai v3 and v4 (see chaijs/chai#744) and as pointed out by #69, currently tests aren't breaking for any version.

There needs to be tests proving .not.property works properly on v3 and breaks on v4, so the v4 transition can be done smoothly.

(This is not a chai v4 issue because it does not require Chai v4, it's the other way around.)

@astorije astorije added this to the v2.0.0 milestone Dec 18, 2016
@astorije
Copy link
Owner Author

Alright, so:

On v1.6.0 (Chai v3):

$ git diff
───────────────────────────────────────────
modified: test/test.js
───────────────────────────────────────────
@ test.js:410 @ describe('chai-immutable (' + typeEnv + ')', function () {
     describe('property property', function () {
       it('should not affect the original assertion', function () {
         expect({ x: 1 }).to.have.property('x', 1);
+
+        expect({ x: 1 }).not.to.have.property('y');
+        expect({ x: 1 }).not.to.have.property('y', 1);
       });

       it('should fail given an inexisting property', function () {
@ test.js:425 @ describe('chai-immutable (' + typeEnv + ')', function () {
         expect(obj).not.to.have.property('z');
       });

+      it('should pass using `not` given an inexisting property and value', function () {
+        var obj = Immutable.fromJS({ x: 1 });
+        expect(obj).not.to.have.property('z', 42);
+      });
+
       it('should pass given an existing property', function () {
         var obj = Immutable.fromJS({ x: 1 });
         expect(obj).to.have.property('x');
  153 passing (141ms)
  2 failing

  1) chai-immutable (Node.js) BDD interface property property should not affect the original assertion:
     Error: { x: 1 } has no property 'y'
      at Assertion.<anonymous> (node_modules/chai/lib/chai/core/assertions.js:895:15)
      at Assertion.ctx.(anonymous function) (node_modules/chai/lib/chai/utils/addMethod.js:41:25)
      at Assertion.<anonymous> (chai-immutable.js:481:28)
      at Assertion.ctx.(anonymous function) [as property] (node_modules/chai/lib/chai/utils/overwriteMethod.js:49:33)
      at Context.<anonymous> (test/test.js:412:38)

  2) chai-immutable (Node.js) BDD interface property property should pass using `not` given an inexisting property and value:
     AssertionError: expected Map { "x": 1 } to have a property 'z'
      at Assertion.<anonymous> (chai-immutable.js:447:21)
      at Assertion.ctx.(anonymous function) [as property] (node_modules/chai/lib/chai/utils/overwriteMethod.js:49:33)
      at Context.<anonymous> (test/test.js:427:33)

On master (Chai v4):

(Same diff, just with ES6 syntax)

$ git diff
───────────────────────────────────────────
modified: test/test.js
───────────────────────────────────────────
@ test.js:398 @ describe('chai-immutable', function () {
     describe('property property', function () {
       it('should not affect the original assertion', function () {
         expect({ x: 1 }).to.have.property('x', 1);
+
+        expect({ x: 1 }).not.to.have.property('y');
+        expect({ x: 1 }).not.to.have.property('y', 1);
       });

       it('should fail given an inexisting property', function () {
@ test.js:413 @ describe('chai-immutable', function () {
         expect(obj).not.to.have.property('z');
       });

+      it('should pass using `not` given an inexisting property and value', function () {
+        const obj = Immutable.fromJS({ x: 1 });
+        expect(obj).not.to.have.property('z', 42);
+      });
+
       it('should pass given an existing property', function () {
         const obj = Immutable.fromJS({ x: 1 });
         expect(obj).to.have.property('x');
  153 passing (186ms)
  1 failing

  1) chai-immutable
       BDD interface
         property property
           should pass using `not` given an inexisting property and value:
     AssertionError: expected Map { "x": 1 } to have a property 'z'
      at Proxy.<anonymous> (chai-immutable.js:233:225)
      at Proxy.overwritingMethodWrapper (node_modules/chai/lib/chai/utils/overwriteMethod.js:78:33)
      at Context.<anonymous> (test/test.js:415:33)

@astorije
Copy link
Owner Author

This confirms that I need to update property when using not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant