kolodny / safetest

MIT License
1.31k stars 31 forks source link

jest is not defined #7

Closed giolazzareschi closed 3 months ago

giolazzareschi commented 3 months ago

Hello!

I've read this https://netflixtechblog.com/introducing-safetest-a-novel-approach-to-front-end-testing-37f9f88c152d And I am willing to learn and integrate Safetest in my current project.

I've installed it like this:

[...] package.json stuff...

"scripts": {
    "safetest": "OPT_URL=${OPT_URL:-http://localhost/supervisor} vitest --config vite.safetest.config.ts"
},
"dependencies": {
    "@fluentui/react-components": "^9.44.0",
    "@typescript-eslint/eslint-plugin": "^5.48.2",
    "@typescript-eslint/parser": "^5.48.2",
    "axios": "^1.2.4",
    "eslint": "^8.32.0",
    "normalize-css": "^2.3.1",
    "react": "^18.2.0",
    "react-datepicker": "^4.12.0",
    "react-dom": "^18.2.0",
    "react-router-dom": "^6.8.0",
    "tsc": "^2.0.4",
    "safetest": "^0.1.10"
  },
  "devDependencies": {
    "@types/node": "^18.14.1",
    "@types/react": "^18.0.26",
    "@types/react-dom": "^18.0.9",
    "@vitejs/plugin-react": "^3.0.0",
    "eslint-config-prettier": "^8.6.0",
    "prettier": "^2.8.3",
    "typescript": "^4.9.3",
    "vite": "^4.0.0",
    "vitest": "^1.2.2"
  }

When I run "npm run safetest" I got

ReferenceError: jest is not defined

❯ globalSetup ../node_modules/safetest/src/jest.ts:32:3 ❯ ../node_modules/safetest/src/jest.ts:47:11 ❯ createBlockFn ../node_modules/safetest/src/blocks.ts:38:7 ❯ Proxy. ../node_modules/safetest/src/jest.ts:41:25

I double read the examples, is there any depedency missing?

This is my simple test so far:

import { describe, it, expect } from 'safetest/jest';

describe('App', () => {
  it('renders without crashing', async () => {
    expect(1).toEqual(1);
  });
});

If I install

Thanks in advance

andlbrei commented 3 months ago

You need to change your import from safetest/jest to safetest/vitest in your test, because you are using vitest instead of jest.

kolodny commented 3 months ago

@andlbrei's answer is correct. @giolazzareschi, does that fix it for you?

kolodny commented 3 months ago

Closing for now, feel free to reopen if the problem persists

giolazzareschi commented 3 months ago

Hey I am very sorry for the late reply,

Thanks @andlbrei !

Yes it did fixed for me,

Thanks a lot!