Giter Club home page Giter Club logo

api-testing-w-jest's Introduction

JEST

You can check example on my repo : https://github.com/aktasevren/filminglocations-API-w-ExpressJS

Alt text

https://engineering.cimri.com/modern-testing-jest-ve-react-testing-library-part1-e9fe517ac845

https://engineering.cimri.com/modern-testing-jest-ve-react-testing-library-part-2-4e687f20f1c0

  • package.json { "scripts": { "test":"jest" } }

  • default => ** tests** , .spec.js , .test.js

https://jestjs.io/docs/expect#methods

  • toBe(booelan, number, string) , toEqual(array, object) , toBeTruthy , toBeFalsy , not.toEqual() , toContain() , toThrow(function) , toMatch , toBeGreaterThan , toBeUndefined , toHaveProperty

  • jest -t keyword =>

  • jest --watch working with git

  • jest --coverage

  • mock

    import axiosMock from "axios";
    
    async function getUsers(){
        try{
            const response = await axiosMock.get("/users");
            return response.data.users;
        } catch(e){
            throw new Error("wrong")
        }
    }
    
    jest.mock("axios")
    
    const fakeUsers = ["Evren","Ahmet","Blabla"]
    
    axiosMock.get.mockResolvedValue({ data : {users:fakeUsers}});
    
    test("gets the users" , async() =>{
        const users = await getUsers();
        expect(users).toEqual(fakeUsers)
    } )
    
    
    

    Not: Async await yapısını kullanmak için test fonksiyonunuzu async yapmanız gerekir.

api-testing-w-jest's People

Contributors

aktasevren avatar

Watchers

 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.