Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@taras
Last active July 22, 2020 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taras/392b9f89a88c0f428af531a91b95f5e6 to your computer and use it in GitHub Desktop.
Save taras/392b9f89a88c0f428af531a91b95f5e6 to your computer and use it in GitHub Desktop.
let app = createAppInteractor();
let signin = createAppInteractor();
describe("sign-in", () => {
describe("when user is anonymous", () => {
beforeEach(async () => {
await app.visit('/sign-in');
});
it("shows sign-in page", () => {
expect(signin.isVisible).toBe(true);
});
it("shows username", () => {
expect(signin.username.isVisible).toBe(true);
});
it("show password", () => {
expect(signin.password.isVisible).toBe(true);
});
});
describe("when user is authenticated", () => {
beforEach(async () => {
await app.authenticate();
});
beforeEach(async () => {
await app.visit('/sign-in');
});
it('navigates user to home page', () => {
expect(app.currentUser).toBe("/");
});
});
});
$ bigtest analyze mocha-example-test.js --type=mocha
BigTest analysis found the following tests in `mocha-example-test.js`
sign-in > when user is anonymous > shows sign-in page
line 6: async () => {
await app.visit('/sign-in');
}
line 10: () => {
expect(signin.isVisible).toBe(true);
}
sign-in > when user is anonymous > shows username
line 6: async () => {
await app.visit('/sign-in');
}
line 14: () => {
expect(signin.username.isVisible).toBe(true);
}
sign-in > when user is anonymous > show password
line 6: async () => {
await app.visit('/sign-in');
}
line 18: () => {
expect(signin.password.isVisible).toBe(true);
}
sign-in > when user is authenticated > navigates user to home page
line 24: async () => {
await app.authenticate();
}
line 28: async () => {
await app.visit('/sign-in');
}
line 32: () => {
expect(app.currentUser).toBe("/");
}
let app = createAppInteractor();
let signin = createAppInteractor();
// This is a optimized version of the test suite above
// We're not going to make these optimizations yet, but
// eventually suggest that we can optimize the test suite this way.
export default test("sign-in")
.child("when user is anonymous",
test => test
.step("user is authenticated", async () => {
await app.visit('/sign-in');
})
.assertion("shows sign-in page", () => {
expect(signin.username.isVisible).toBe(true);
})
.assertion("shows username", () => {
expect(signin.username.isVisible).toBe(true);
})
.assertion("show password", () => {
expect(signin.password.isVisible).toBe(true);
}))
.child("when user is authenticated", test => test
.step(async () => {
await app.authenticate();
})
.step(async () => {
await app.visit('/sign-in');
})
.assertion("navigates user to home page", () => {
expect(app.currentUser).toBe("/");
});
@cowboyd
Copy link

cowboyd commented Jul 22, 2020

I order to educate and explain the difference, it would be helpful to also provide a countervailing analysis of the bigtest suite. For example, in this example you go from four test cases to having just two (one for each child).

We could include a summary in the in

BigTest analysis found 4 test case(s) tests in `mocha-example-test.js`
-> an upgrade to BigTest can optimize this to 2 tescase containing

Or something like that.

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