jeudi 25 juin 2020

How to make Mocha to check mutating object in real time?

In the "test1", the property value foo of testObject already became to bravo. Thus, both "test1" and "test2" will fail.

import { assert as Assert } from "chai";

describe("test", (): void => {

  const testObject: { foo: string; } = { foo: "alpha" };

  it("test1", (): void => {
    Assert.deepEqual(testObject, { foo: "alpha" }); 
  });

  testObject.foo = "bravo";
  it("test2", (): void => {
    Assert.deepEqual(testObject, { foo: "bravo" });
  });
});

I need to solve this for testing of my function, which among it's functionality clones the array:

  1. Create array
  2. Deeply clone array
  3. Check has array been cloned correctly
  4. Mutate cloned array (will break step 3 tests)
  5. Make sure that initial array was not changed

Aucun commentaire:

Enregistrer un commentaire