Skip to content

Instantly share code, notes, and snippets.

@ZackDeRose
Last active January 15, 2019 00:49
Show Gist options
  • Save ZackDeRose/cab879c2b521c5e7f45b28000cf03483 to your computer and use it in GitHub Desktop.
Save ZackDeRose/cab879c2b521c5e7f45b28000cf03483 to your computer and use it in GitHub Desktop.
describe('Foo Class', () => {
describe('constructor', () => {
const fooClassRef = Foo as any; // to pass typechecking
beforeEach(() => {
console.log(`start of beforeEach: ${fooClassRef._count}`);
fooClassRef._count = 0;
console.log(`end of beforeEach: ${fooClassRef._count}`);
});
describe('creating one Foo obj', () => {
console.log(fooClassRef._count);
const foo = new Foo();
it('should have an id of 1', () => {
expect(foo.id).toBe(1);
});
});
describe('creating two Foo objs', () => {
console.log(fooClassRef._count);
const foo1 = new Foo();
const foo2 = new Foo();
it('should have ids of 1 and 2', () => {
expect(foo1.id).toBe(1);
expect(foo2.id).toBe(2);
});
});
});
});
@LayZeeDK
Copy link

A little white space goes a long way. At least, it makes it clearer to me where you went wrong. It took a moment to notice.

describe('Foo Class', () => {
  describe('constructor', () => {
    const fooClassRef = Foo as any; // to pass typechecking

    beforeEach(() => {
      console.log(`start of beforeEach: ${fooClassRef._count}`);
      fooClassRef._count = 0;
      console.log(`end of beforeEach: ${fooClassRef._count}`);
    });

    describe('creating one Foo obj', () => {
      console.log(fooClassRef._count);
      const foo = new Foo();

      it('should have an id of 1', () => {
        expect(foo.id).toBe(1);
      });
    });

    describe('creating two Foo objs', () => {
      console.log(fooClassRef._count);
      const foo1 = new Foo();
      const foo2 = new Foo();

      it('should have ids of 1 and 2', () => {
        expect(foo1.id).toBe(1);
        expect(foo2.id).toBe(2);
      });
    });
  });
});

@ZackDeRose
Copy link
Author

👍

@ZackDeRose
Copy link
Author

Updated. Ty!

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