React Testing Tutorial - 14 - Code Coverage

Поделиться
HTML-код
  • Опубликовано: 24 янв 2025

Комментарии • 75

  • @krishnanigalye1173
    @krishnanigalye1173 2 года назад +38

    To make it work with npm, use the following code.
    "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "coverage": "npm test -- --coverage"
    },

    • @shankars101
      @shankars101 2 года назад

      Thank you

    • @elik3765
      @elik3765 2 года назад

      I keep getting 'Unknown command: "coverage"' error. node vv18.13.0

    • @lox_07
      @lox_07 Год назад +5

      @@elik3765 try using "coverage": "npm run test -- --coverage" and in cli, npm run coverage

    • @Asli_
      @Asli_ Год назад

      @@lox_07 not working

    • @mohanant7557
      @mohanant7557 Год назад +1

      @@Asli_ use react-scripts test --coverage

  • @vanshajkapoor998
    @vanshajkapoor998 Год назад +8

    For npm users use this : {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "coverage": "npm test -- --coverage --watchAll"
    }

  • @djbuffonage9500
    @djbuffonage9500 Год назад +6

    I am using npm and this is how I got it to work
    1) added "coverage": "react-scripts test --coverage --watchAll" to the scripts section
    2) npm run coverage
    I am using node version 18.16.1

  • @code_with_sheynet
    @code_with_sheynet 2 года назад +2

    You the best, sir
    You tutorial video is My back bone, I just love you! Only your tutorial i understand...

  • @jnaras
    @jnaras Год назад

    Nice. Great work Vishwas.

  • @sairamgudiputi8
    @sairamgudiputi8 Год назад +7

    To generate coverage report:
    "coverage": npm test -- --coverage --watchAll
    note: extra double dashes after test.

    • @Lohitpant
      @Lohitpant Год назад

      thats working for npm.

    • @SaifChowdhuryFardin
      @SaifChowdhuryFardin Год назад

      thanks for the "note". i was missing that extra double dashes

  • @rickyreyes30
    @rickyreyes30 Год назад

    Thank you! This was very helpful. Saved me a ton of time and exactly what I was looking for.

  • @ronaldolipata1455
    @ronaldolipata1455 2 года назад +8

    If you use npm and this doesn't work for you
    "coverage" : "npm test -- -- coverage"
    Try this instead, it worked for me.
    "coverage": "react-scripts test --coverage"
    Then run
    npm coverage or npm run coverage

  • @saisashankchavaly2121
    @saisashankchavaly2121 2 года назад +2

    Testing tutorials are very good and very informative .

  • @botchu4597
    @botchu4597 8 месяцев назад +1

    For NPM users:
    "coverage": "npm test -- --coverage --watchAll"
    Note: use the extra double dash -- after test to work

  • @alweenaiqbal1088
    @alweenaiqbal1088 2 года назад +10

    use following scripts if you don't see the uncovered files-
    "test": "react-scripts test -u --watchAll" ,
    "coverage": "npm test -- --coverage"
    and then run the command - npm run coverage

  • @chtarun2800
    @chtarun2800 9 месяцев назад

    Amazing Work!!
    Thanks

  • @piyushaggarwal5207
    @piyushaggarwal5207 Год назад +7

    This is the final script I had using NPM
    "coverage": "react-scripts test --coverage --watchAll --collectCoverageFrom='src/components/**/*.{ts,tsx}' --collectCoverageFrom='!src/components/**/*.{types,stories,constants,test,spec}.{ts,tsx}'"

  • @adittttya
    @adittttya Год назад

    You are a LEGEND!🔥

  • @Lohitpant
    @Lohitpant Год назад

    this video is very informative and useful for me. Thanks.

  • @Theokondak
    @Theokondak Год назад

    Thank you very much! You nailed it!

  • @clnia_dev
    @clnia_dev 3 месяца назад

    What does "statements": -10 mean? Does it mean it will fail if there are no statements executed?

  • @parthadhikari00
    @parthadhikari00 Год назад +1

    For npm users:
    "coverage": "react-scripts test --coverage --watchAll --collectCoverageFrom='src/components/**/*.{ts,tsx}' --collectCoverageFrom='!src/components/**/*.{types,stories,constants,test,spec}.{ts,tsx}'"

  • @ParthKamal-rr4nr
    @ParthKamal-rr4nr 9 месяцев назад

    How can i use to get the code coverage of my selenium tests in the react app? can you give me any solution for that ?

  • @otherme8212
    @otherme8212 2 года назад +1

    For People Running into issues for getting the test coverage in case of npm
    Run the Following Command
    npm i -D --exact jest-watch-typeahead@0.6.5
    This worked For me !! Thanks !!!

  • @crashcoding6667
    @crashcoding6667 Год назад

    What is branch coverage? why you showed ternary operator?

  • @1004robinson
    @1004robinson 2 года назад

    Thanks a lot

  • @imhimmazi7999
    @imhimmazi7999 8 месяцев назад

    Using npm, i added the following to the script:
    "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "coverage": "react-scripts test --coverage --watchAll"
    },
    Windows OS, Node v20.12.2

  • @061_suryak4
    @061_suryak4 2 года назад

    hi, i got error like could not find react-redux context value; please ensure the component is wrapped in a
    but i also wrapped by provider within store and i change old to latest version please gave me a any solution

  • @raghavi_kannan
    @raghavi_kannan Год назад

    I tried getting coverage from also the __tests__ folder using the command below.
    npm test -- --coverage --watchAll --collectCoverageFrom='src/{components,__tests__}/**/*.{ts,tsx}' but the coverage report did not include the tests folder. what is the mistake here?

    • @vinothm7899
      @vinothm7899 Год назад

      Add it at the end for the package.json file
      "jest": {
      "collectCoverageFrom": [
      "src/**/*.tsx",
      "src/components/*.tsx",
      "!**/node_modules/**",
      "!**/src/test-utils/**",
      "!**/src/index.tsx"
      ],
      "coverageThreshold": {
      "global": {
      "statements": 100,
      "branches": 100,
      "functions": 100,
      "lines": 100
      }
      }
      }

  • @cyberboxingleagueoffical
    @cyberboxingleagueoffical 2 года назад

    using --watchAll makes all my tests pass while --watchAll=false gets some of them to fail, any idea why? Also, is there a way for you to exit script after running all the tests with the way you have it set up now? Any help would be appreciated. Thanks!

  • @achalagawai3960
    @achalagawai3960 Год назад

    Can you tell me why the test cases are passing but coverage is not increasing.😢😢😢

  • @yuliyadykava2540
    @yuliyadykava2540 2 года назад

    thanks for the video! btw is there a way to run only one testing file and create coverage html report only for this file? without running all other tests

  • @rajatpratapsingh3123
    @rajatpratapsingh3123 2 года назад +1

    npm test -- --coverage

  • @shashankkumar1633
    @shashankkumar1633 Год назад

    what is the meaning of **/* in collectCoverageFrom. it is not explained.

  • @KumarKumar-gf3pp
    @KumarKumar-gf3pp 2 года назад

    how to get that coverage folder...?

  • @amitagrawal4494
    @amitagrawal4494 Год назад

    @Codevolution - Can you please let us know how to use code coverage if we are using npm not yarn.

    • @jakubgodlewski2506
      @jakubgodlewski2506 Год назад

      the first comment here in the comment section describes it

  • @jenricdota
    @jenricdota Год назад

    Hi I have a question, why does it become 50%? I'm really confused. Also how to make it 100%? thanks

  • @loganathanchellappan8329
    @loganathanchellappan8329 2 года назад

    "coverage" : "npm test -- -- coverage" try this code it's working

  • @xiaotingshao3689
    @xiaotingshao3689 2 года назад

    it doesn't work for me, i have to use this command to run:
    npm run test -- --coverage

  • @naveencrazy5214
    @naveencrazy5214 Год назад

    coverage": "react-scripts test --coverage --watchAll --collectCoverageFrom='src/components/**/*.{ts,tsx}' --collectCoverageFrom='!src/components/**/*.{types,stories,constants,test,spec}.{ts,tsx}'" not working

  • @marcus_leon
    @marcus_leon 2 года назад +15

    Try this if it doesn't work: "coverage": "npm test -- --coverage"

  • @somewhere_in_bharat
    @somewhere_in_bharat 9 месяцев назад

    I am getting 0 in my test coverage table

  • @pupil_1
    @pupil_1 Год назад

    npm test -- --coverage , for npm users

  • @krishnakishore8111
    @krishnakishore8111 2 года назад +1

    "coverage": "npm test -- --coverage"
    or
    "npm run test -- --coverage"
    both commands are not working for me its not showing any code coverage table
    I googled it and following command working for me
    npm test -- --coverage --watchAll=false

  • @poojanb3566
    @poojanb3566 Год назад

    Hi

  • @exxedridel9043
    @exxedridel9043 2 года назад

    Good video, but some lack of explanations, and you don't respont to community answers so can't like it

  • @aitfrihaZaid
    @aitfrihaZaid Год назад

    i deleted ,stories,constants,test,spec it shoud works because i want not to display files with .types.tsx but its not working
    "coverage": "react-scripts test --coverage --watchAll --collectCoverageFrom='src/components/**/*.{ts,tsx}' --collectCoverageFrom='!src/components/**/*.{types}.{ts,tsx}'"

    • @annavimathi6843
      @annavimathi6843 Год назад

      How to open this report of html I wasn't to do it