Search code examples
node.jsexpressmocha.jssupertestnode-mongodb-native

How can something be neither deepStrictEqual or notDeepStrictEqual?


I was testing my REST API with supertest and mocha+standard assert and I ran into this issue where both test cases return false, by the way Mongo is returning an error, so I know one will be false but why both?

    describe("GET /2/test", () => {
        let data = Object.create(sampleData);
        data.type = "test";

        it("responds with the correct document to correct input", function() {
            return request(app)
                .get(`/2/test`)
                .set('Accept', 'application/json')
                .expect('Content-Type', /json/)
                .then(res => {
                    assert.deepStrictEqual(res.body.field1, data.field1);
                    assert.deepStrictEqual(res.body.field2, data.field2);
                });
        });
        it("responds with something else to false input", function() {
            return request(app)
                .get(`/2/test`)
                .set('Accept', 'application/json')
                .expect('Content-Type', /json/)
                .then(res => {
                    assert.notDeepStrictEqual(res.body.field1, data.field1);
                    assert.notDeepStrictEqual(res.body.field2, data.field2);
                });
        });

    });

Solution

  • If they are undefined apparently, so if you are running into this error make sure the variables being compared aren't undefined. It wasn't defined because I was using Object.create(sampleData); instead of Object.assign(sampleData);