Skip to content

Commit

Permalink
Fixed case where slow tests would fail due to fixture changing over time
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhenry committed Apr 6, 2016
1 parent 475e000 commit 69369a7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"gulp-typescript": "^2.7.6",
"gulp-util": "^3.0.5",
"inquirer": "^0.8.5",
"istanbul": "0.4.2",
"istanbul": "^1.0.0-alpha.2",
"istanbul-instrumenter-loader": "0.1.3",
"karma": "0.13.22",
"karma-chai-plugins": "^0.7.0",
Expand Down
11 changes: 8 additions & 3 deletions src/fixtures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import * as moment from "moment";
import {IJwtToken, IUser} from "./ngJwtAuthInterfaces";

let seededChance:Chance.Chance = new Chance(1);

let loadedToken:string;

export const fixtures = {
loginPrompt:null,
user: {
_self: '/users/1',
userId: 1,
email: '[email protected]',
firstName: seededChance.first(),
Expand Down Expand Up @@ -50,8 +53,10 @@ export const fixtures = {
},

get token(){

return fixtures.buildToken(); //no customisations
if (!loadedToken){
loadedToken = fixtures.buildToken(); //no customisations
}
return loadedToken; //this "caching" ensures the token is unchanged between tests if they take too long (otherwise the timestamps may differ)
}
};

Expand Down
1 change: 0 additions & 1 deletion src/service/ngJwtAuthService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,6 @@ describe('Service tests', () => {
let userToImpersonate = fixtures.userResponse;

userToImpersonate.userId = 2;
userToImpersonate._self = '/users/2';

let expectedToken = fixtures.buildToken({
data: {
Expand Down

0 comments on commit 69369a7

Please sign in to comment.