Skip to content

One day JavaScript workshop for PP Sunday. Easy ~ Intermediate

License

Notifications You must be signed in to change notification settings

PinkProgramming/js-testing-intro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Intro

Slides

What is NodeJS?

If you already started to learn JS, you know JS (JavaScript) is code that run in a web browser from a webpage. To write unit tests in JS you probably want something different. These should not be in browser. If so, they probably doing user input validation (not unit test).

To run tests in JS you need a test runner. This is a small program that automatically detects any tests you created and runs them. The results are presented to you as a developer only, either in a terminal, or as a simple webpage.

When running tests in a terminal, you need a Javascript engine suitable for it. In most cases this is NodeJS, which you can install just like you install Java, Python or any programming language you want to code in. You may also run it in the cloud, for example using Codesandbox as suggested bellow.

Project Setup

Codesandbox

Codesandbox is an cloud-based developer environment where you can code frontend, backend or fullstack without downloading anything.

Getting started

Open this codesandbox link, then:

  1. Fork sandbox using the top right button. This requires that you sign up with your Github account and Google account.
  2. Wait for startup animation to finish.
  3. Navigate to Server Control Panel .
  4. Click 🧪 yarn test to start the test-runner.
  5. Resize the terminal panel if needed.

Local development

**This is needed if network is slow, or codesandbox is failing in other way

Installation

You need to have Node/NPM downloaded and installed. Verify your installation with terminal commands node -v and npm -v,

Setup

Alternative A. Open a console, cd into to your local workspace folder, run 1) git clone https://github.com/PinkProgramming/js-testing-intro.git, 2) cd js-testing-intro, 3) npm install 4) npm run test

Alternative B. An empty project is created, like with any NodeJS project, in the console. then enter:

  mkdir my-nodejs-tests
  cd my-nodejs-tests
  npm init

In order to run tests, an extra npm package is needed. We will use Jest, a popular one, also used in ReactJS, Angular, Typescript. Add the package like so:

  npm install --save-dev jest

then add the test runner to package.json inside "scripts":

{
  "test": "jest --watchAll --verbose"
}

Now start the testing with terminal command:

  npm run test

Exercises

Solutions

https://codesandbox.io/s/js-testing-intro-solutions-3o6h9

or

https://github.com/PinkProgramming/js-testing-intro/tree/solutions

About

One day JavaScript workshop for PP Sunday. Easy ~ Intermediate

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published