This file contains hidden or 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
## Testing with TypeScript | |
| |
<br/> | |
| |
Yes, TypeScript(TS) allows us to be strict with the `types` of data we call functions with and the types we allow to be returned - how that data should look. However, TS doesn't have any impact on our logic, or prevent a function returning data with an incorrect value. | |
| |
Therefore, the need for testing remains and TS can work with TDD to allow for cleaner tests that only test the behaviour of our code, with TS handling any edge cases. | |
| |
TS compiles down to JavaScript(JS), meaning there are many Node.js compatible testing frameworks available with great documentation. These include [Mocha](https://mochajs.org/Mocha) (testing framework) and [Chai](https://www.chaijs.com/) (assertion library) or [Jest](https://jestjs.io/) (framework _and_ library). Most frameworks behave in a similar way so the the choice is yours. | |
|
This file contains hidden or 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
# Type Basics | |
### Type declaration | |
There are several ways we can declare type in TS | |
ts | |
let word: string = "test"; | |
let num: number = 101; | |
let words: string[] = ["this", "is", "an", "array", "of", "strings"]; |
This file contains hidden or 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
**Creating a New Project** | |
1. Create a folder on your computer and start your work in VSc | |
2. Create a Repo on GITHub. | |
3. Then put these into GIT: | |
git init | |
git add . | |
git commit -m "first commit" | |
git branch -M main | |
git remote add origin https://github.com/URL.git |
This file contains hidden or 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
// Match Function | |
db.articles.aggregate([ { $match : { author : "dave" } } ]); |
This file contains hidden or 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
// Original Functions | |
(hello = function() { | |
return "Hello World!" | |
}()) // By putting the () at the end this invokes the function | |
// Arrow Function | |
hello = () => { | |
return "Hello World!" | |
} |