Welcome to the Linux Foundation Forum!

lab 16 3: cannot get line 11 covered

Howdy all,

I know that may seem trivial, but as the title states, I cannot get a line covered. This line it says I'm not covering is the result.

I've set up mocks for math and the timer. I do a check to see what the value is (see test: buffer, should return value below), and yet jest w/ coverage says I do not have it covered. Am I missing something here?

  1. describe('store tests', () => {
  2. let store;
  3.  
  4. beforeEach(() => {
  5. jest.spyOn(Math, 'random').mockReturnValue(0.5);
  6. global.setTimeout = require('timers').setTimeout;
  7. store = require('./store');
  8. })
  9. afterEach(() => {
  10. jest.restoreAllMocks();
  11. jest.resetAllMocks();
  12. store = null;
  13. })
  14. test('should error', async () => {
  15. try {
  16. await store(undefined)
  17. }catch (e){
  18. expect(e.message).toEqual('input must be a buffer')
  19. }
  20. });
  21. test('buffer, should return value', async () => {
  22. const val = await store(Buffer.from((1).toString()))
  23. expect(val).toEqual(({"id": "i"})); // I check for the reuslt value.
  24. });
  25. });
  26.  
  1. //coverage result
  2.  
  3. 1 |1x 'use strict'
  4. 2 |1x const { promisify } = require('util')
  5. 3 |1x const timeout = promisify(setTimeout)
  6. 4 |1x module.exports = async (value) => {
  7. 5 |2x if (Buffer.isBuffer(value) === false) {
  8. 6 |1x throw Error('input must be a buffer')
  9. 7 |1x }
  10. 8 |1x await timeout(300)
  11. 9 |1x const id = Math.random().toString(36).split('.')[1].slice(0, 4)
  12. 10 |2x return { id }
  13. 11 }
  14. 12

in coverage, line 10 is highlighted in yellow, and line 11 is highlighted pink.

Thanks,
Kellly

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Comments

  • Posts: 19

    Tried again by doing another speed run , and I still have that line not being covered:

    1. describe('store test', function () {
    2. // ...
    3. describe('and buffer value', function () {
    4. test('should fail', async () => {
    5. expect.assertions(1);
    6. const actual = await store(Buffer.from('some value'));
    7.  
    8. const expected = {id: 'i'};
    9. expect(actual).toEqual(expected)
    10. });
    11. });
    12. });
    13.  
  • Posts: 19

    I think I have the issue figured out... it was because I chose 'v8' instead 'babel' for jest

  • glad you figured it out @kellv - I'm not much of a jest or babel user 😅

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training