Skip to content

Instantly share code, notes, and snippets.

@MatLang
Last active June 19, 2019 06:54
Show Gist options
  • Save MatLang/cf95ff743315842e29b6825fe66bb4e3 to your computer and use it in GitHub Desktop.
Save MatLang/cf95ff743315842e29b6825fe66bb4e3 to your computer and use it in GitHub Desktop.
Async testing examples #testing
import { isMainThread } from "worker_threads";
fdescribe("Async testing examples", () => {
it("Asynchronous test example with jasmine done()", (done: DoneFn) => {
let test = false;
setTimeout(() => {
console.log("running assertions");
test = true;
expect(test).toBeTruthy();
done();
});
});
it("Asynchronous test example with jasmine tick()", fakeAsync(() => {
let test = false;
setTimeout(() => {
console.log("running assertions");
test = true;
}, 1000);
tick(1000);
expect(test).toBeTruthy();
}));
it("Asynchronous test example with jasmine flush()", fakeAsync(() => {
let test = false;
setTimeout(() => {
console.log("running assertions");
test = true;
}, 1000);
flush();
expect(test).toBeTruthy();
}));
it("Asynchronous test with promises with flushMicrotasks()", fakeAsync(() => {
let test = false;
Promise.resolve().then(() => {
test = true;
});
flushMicrotasks();
expect(test).toBeTruthy();
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment