---
title: "Guide - Så gör du när du inte vill köra alla tester varje gång"
metaTitle: "1DV025 | JSDoc"
metaDescription: "metaDescription"
order: 4
---

1. Öppna `package.json` och lägg till skriptet
2. `"test:only": "npx --node-options=--experimental-vm-modules jest -t"` sist
3. bland skripten (glöm inte att lägga till ett kommatecken efter det näst sista
4. skriptet).

    ```json
    {
      "name": "assignment-a2-descriptive-statistics",
      "version": "1.2.0",
      "description": "1DV025 - Assignment A2 - Descriptive Statistics",
      "type": "module",
      "main": "src/app.js",
      "scripts": {
        "start": "node src/app.js",
        "lint": "npx eslint ./src || exit 0",
        "lint:fix": "npx eslint ./src --fix || exit 0",
        "test": "npx --node-options=--experimental-vm-modules jest || exit 0",
        "test:only": "npx --node-options=--experimental-vm-modules jest -t"
      },
      ...
    ```

5. Spara `package.json` filen.
6. Kör alla tester med `npm test` och studera resultatet. Konstatera att det
7. finns namn specificerade som till exempel _average_, _argument_,
8. _exceptions_. Dessa namn kan användas för att begränsa vilka tester som ska köras.

    ```terminal
    > assignment-a2-descriptive-statistics@1.2.0 test
    > npx --node-options=--experimental-vm-modules jest || exit 0


    (node:32892) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
    (Use `node --trace-warnings ...` to show where the warning was created)
    FAIL  test/statistics.test.js
      average
        argument
          exceptions
            × passing anything but an array should throw TypeError with the custom message 'The passed argument is not an array.' (6 ms)
            × passing an empty array should throw Error with the custom message 'The passed array contains no elements.' (2 ms)
            × passing an array containing a value that is not of the type number should throw TypeError with the custom message 'The passed array may only contain valid numbers.' (2 ms)
            × passing an array containing the value Number.NaN should throw TypeError with the custom message 'The passed array may only contain valid numbers.' (1 ms)
            × passing a large array (200000 elements) should not throw an exception (33 ms)
          side effects
            × passing [4, 2, 6, 1, 3, 7, 5, 3] should return a value and not modify the argument (1 ms)
        return value
          × passing [-2, 5, 1, 1, 5, 5, 2, -2, 2, -2] should return 1.5
          × passing [-42, -84, -2, -3] should return -32.75
    ...
    ```

9. För att köra testerna som har med average att göra kör skriptet `test:only`
10. och skicka med `"average"` som ett argument.

    ```terminal
    npm run test:only "average"
    ```

11. Enbart de tester som återfinns under namnet _average_ kommer att köras.

    ```terminal
    > assignment-a2-descriptive-statistics@1.2.0 test:only
    > npx --node-options=--experimental-vm-modules jest -t average

    (node:31480) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
    (Use `node --trace-warnings ...` to show where the warning was created)
    FAIL  test/statistics.test.js
      average
        argument
          exceptions
            × passing anything but an array should throw TypeError with the custom message 'The passed argument is not an array.' (4 ms)
            × passing an empty array should throw Error with the custom message 'The passed array contains no elements.' (1 ms)
            × passing an array containing a value that is not of the type number should throw TypeError with the custom message 'The passed array may only contain valid numbers.' (1 ms)
            × passing an array containing the value Number.NaN should throw TypeError with the custom message 'The passed array may only contain valid numbers.' (1 ms)
            × passing a large array (200000 elements) should not throw an exception (30 ms)
          side effects
            × passing [4, 2, 6, 1, 3, 7, 5, 3] should return a value and not modify the argument
        return value
          × passing [-2, 5, 1, 1, 5, 5, 2, -2, 2, -2] should return 1.5
          × passing [-42, -84, -2, -3] should return -32.75
      maximum
        argument
          exceptions
            ○ skipped passing anything but an array should throw TypeError with the custom message 'The passed argument is not an array.'

    <OUTPUT OMITTED FOR CLARITY!>

    Test Suites: 1 failed, 1 total
    Tests:       10 failed, 60 skipped, 70 total
    Snapshots:   0 total
    Time:        1.175 s
    Ran all test suites with tests matching "average".
    ```

12. Vill du istället köra testerna som återfinns under namnet _maximum_, och
13. hoppa över alla andra, kör du skriptet `test:only` och skicka med
14. `"maximum"` som ett argument.

    ```terminal
    npm run test:only "maximum"
    ```
