Code Monkey home page Code Monkey logo

ud549's Introduction

JavaScript Testing

Framework used: Jasmine

describe statements are used to identify a suite, which are a group of related specs. It provides a level of indentation.

it statements are used to identify a specification ie a container for feature we are testing. If all expectations within a spec return true, it passes. If any of the expectations were to return false, the spec would fail.

expect is the launching point of any test. It accepts a single value called the actual function.

matcher The comparison method used is called the matcher and is chained after the call to expect. We pass the expected value to the matcher. There are a lot of matcher functions and we can create our own too.

toBe tests for strict equality not.toBe can be used to negate a test

Red Green Refactor cycle

  • You write your tests and they all fail since there's no code to make them pass.
  • You then write the code to make your tests pass
  • Now you can safely refactor your code and add new features.

beforeEach(), afterEach() can be used to remove redundant code

Testing async code We cannot run expect statements inside the callback function as they'll be run within the scope of our application and not the testing framework.

done() It signals to the testing framework when an async function has completed.

ud549's People

Contributors

saumya29 avatar hkasemir avatar

Watchers

James Cloos avatar  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.