Git Product home page Git Product logo

js-testing-intro's Introduction

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

js-testing-intro's People

Contributors

rikku-pp avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.