(disclaimer: I’m getting started with testing)
I’m using velocity + jasmine, doing client integration tests. I want to test two different behavior that depend on a Session variable set accordingly to the url parameter. I’m struggling to write two tests that would be totally independent, as if two different users where doing them. Here is what I have:
describe('Case A', function() {
beforeEach(function (done) {
Router.go('home');
this.deferAfterFlush(done);
});
beforeEach(waitForRouter);
it("doesnt show the Signup button", function() {
console.log('case A', Session.get('signupAuth'), $("#signup-link").length);
expect($("#signup-link").length).toEqual(0);
});
});
describe('Case B', function() {
beforeEach(function(done) {
Router.go('home', {}, {query: {signupCode: 'superCode'}});
this.deferAfterFlush(done);
});
beforeEach(waitForRouter);
it("shows the Signup button", function() {
console.log('case B', Session.get('signupAuth'), $("#signup-link").length);
expect($("#signup-link").length).toEqual(1);
});
});
When there is a signupCode
parameter, it is saved in the Session ‘signupAuth’ and I redirect to ‘/home’.
When rendering ‘home’, this Session variable is checked and $("#signup-link")
is only created if the variable is set.
waitForRouter
is from https://meteor-testing.readme.io/docs/jasmine-integration-tests-with-iron-router
It seems that those tests are not independent. The Session variable set in ‘Case B’ is accessible from ‘Case A’ and this screws up everything. (I can see that from the logs and I’m pretty sure my client code is working correctly)
Each test works well if the other is not running.
Am I doing something wrong? How can I make those two tests be independent, as if they were running in two separate mirrors?
Thanks a lot!