Skip to content

Instantly share code, notes, and snippets.

@denniske
Created November 21, 2018 12:53
Show Gist options
  • Save denniske/311462d87106246e0944147777e0fb3d to your computer and use it in GitHub Desktop.
Save denniske/311462d87106246e0944147777e0fb3d to your computer and use it in GitHub Desktop.
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