Skip to content

daniellee862/jest-testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jest Testing 🤹‍♂️

Test Driven Development (TDD) practice by testing a range of functions with different inputs. My goal was to ensure that each function returned the correct output when given a variety of inputs. 💯

I also made sure to consider edge cases where the function might have to deal with unexpected, unusual, or incorrect inputs. And by testing "interfaces not implementations," I focused on what my function returns when given some input, rather than trying to test what's happening inside the function or whether it is being used correctly. 🤓

Documentation 📖

I've included a helpful blog post by Eric Elliott and links to the Jest documentation to guide you along the way.

Blog post by Eric Elliott

Jest documentation

Running Tests

Simply run the "npm test" command to test every function in the tests folder.

  npm run test

Usage/Examples

const checkStudents = require("../katas/check-students");

describe("checkStudents", () => {
    test("returns empty array when passed empty array", () => {
        expect(checkStudents([])).toEqual([]);
    });

    test("returns false when passed array with 2 different cohorts", () => {
        expect(checkStudents([{name: 'Ben', cohort: 'October'},
        {name: 'Amanda', cohort: 'April'}], 'April')).toEqual(false);
    });

    test("returns true when passed array with 2 same cohorts", () => {
        expect(checkStudents([{name: 'Amanda', cohort: 'April'},
            {name: 'Matt', cohort: 'April'}], 'April')).toEqual(true);
    });

    test("returns false when passed array with multi cohorts", () => {
        expect(checkStudents([{name: 'Ben', cohort: 'October'},
            {name: 'Amanda', cohort: 'April'},
            {name: 'Matt', cohort: 'April'},
            {name: 'Daniel', cohort: 'November'},
            {name: 'Dee', cohort: 'November'}], 'November')).toEqual(false);
    });
})

About

Test-Driven development using the Jest Javascript testing framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published