Skip to content

The last Jest test always fails! Learn how to fix it. #14

@julianovmartins

Description

@julianovmartins

This is just a minor bug in this project's repository. In time, Udacity will fix it.

There is a slight problem with the last Jest test (paying less than total works), as the variable (totalPaid) that holds the received cash and supports the pay() function is being initialized with the value (100000000000000) from the previous test.

If you want all ten tests to succeed, add two new lines of code in the:
https://github.com/udacity/cd2073-intro-to-js-1-project-starter/blob/main/starter/tests/script.test.js#L74

To fix this, reset the loaded module and require it again in the last jest test:

test('pay less than the total works', () => {

        // reset the module
        jest.resetModules();

        // require it again
        const cart = require('../src/assets/script.js');


        cart.addProductToCart(product1.productId);
        cart.addProductToCart(product2.productId);
        expect(cart.pay(1)).toBeLessThan(grandTotal());
    });

Now if all your functions are correct, all Jest tests will pass!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions