Created
November 21, 2018 12:53
-
-
Save denniske/311462d87106246e0944147777e0fb3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
expect.extend({ | |
toHaveBeenCalledWithSome<A>(received: (a: A) => any, argument: (a: A) => void) { | |
const [a] = (received as jasmine.Spy).calls.allArgs()[0]; | |
argument(a); | |
return { | |
message: () => "", | |
pass: true | |
}; | |
} | |
}); | |
const greeter = { | |
welcome: (name: string) => { | |
const action = { | |
message: "Welcodme " + name | |
}; | |
console.log(action); | |
} | |
}; | |
describe("greeter", () => { | |
it("'welcome' creates action with welcome message", () => { | |
spyOn(console, "log"); | |
let name = "John"; | |
greeter.welcome(name); | |
expect(console.log).toHaveBeenCalled(); | |
expect(console.log).toHaveBeenCalledWithSome((action: any) => { | |
expect(action).toBeTruthy(); | |
expect(action.message).toContain("Welcome"); | |
expect(action.message).toContain(name); | |
expect(action.message).toBe("Welcome " + name); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment