adding basic jest tests

This commit is contained in:
Ken
2019-02-15 20:23:26 -08:00
parent 988aea6c1d
commit f019207dba
4 changed files with 28 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ async function fetchSomething() {
return await response.text();
}
// Async functions always returns Promise
fetchSomething().then(text => {
console.log('hello ' + text);
});

8
step2-04/index.html Normal file
View File

@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<body>
For this step, we look at unit testing. Run
<pre>npm test</pre>
in the command line.
</body>
</html>

16
step2-04/index.spec.ts Normal file
View File

@@ -0,0 +1,16 @@
import { square } from '.';
describe('square', () => {
beforeEach(() => {
console.log('this happens before each test');
});
afterEach(() => {
console.log('this happens after each test');
});
it('should be able to give the square of two numbers', () => {
console.log('test');
expect(square(5)).toBe(25);
});
});

3
step2-04/index.ts Normal file
View File

@@ -0,0 +1,3 @@
export function square(x: number) {
return x * x;
}