Last active
June 19, 2019 06:54
-
-
Save MatLang/cf95ff743315842e29b6825fe66bb4e3 to your computer and use it in GitHub Desktop.
Async testing examples #testing
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
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