odottaa
odottaa copied to clipboard
Unable to use odottaa in Es6 project
When I try using odotta in a test, I run into the following error:
TypeError: expect.extend: `default` is not a valid matcher. Must be a function, is "object"
I noticed a similar issue had been created, so I tried the suggested change, but it didn't work. I've also tried various import styles, but I can't find one that works. I'm still learning my way around playwright with eslint and typescript, so I may have overlooked something.
Project code: odottaa-example.zip
api.spec.js
import {expect, test} from "@playwright/test"
import playwrightApiMatchers from 'odottaa'
const API_URL = 'https://swapi.dev/api/people/1'
test.describe("Test API asserts", () => {
test('with odottaa', async ({context}) => {
let response = await context.request.get(API_URL)
expect.extend(playwrightApiMatchers)
await expect(response).toBeOK()
await expect(response.json()).toMatchJSON({name: "Luke Skywalker"})
})
})
package.json
{
"name": "odottaa-example",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "index.js",
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.43.1",
"@types/node": "^20.12.8"
},
"dependencies": {
"eslint": "^9.1.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-playwright": "^1.6.0",
"eslint-plugin-prettier": "^5.1.3",
"odottaa": "^1.1.19",
"prettier": "^3.2.5"
}
}
jsconfig.json
{
"compilerOptions": {
"target": "ES6",
"module": "node16",
"moduleResolution": "node16",
"esModuleInterop": true
},
"exclude": [
"node_modules",
"playwright.config"
]
}
playwright.config.js
// eslint-disable-next-line imported/no-unresolved
import playwright from 'eslint-plugin-playwright'
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
import imported from 'eslint-plugin-import'
export default [
playwright.configs['flat/recommended'],
eslintPluginPrettierRecommended,
{
files: ['**/*.*js'],
languageOptions: {
ecmaVersion: 2024,
sourceType: 'module',
globals: {
process: 'readonly',
},
},
plugins: {
imported,
},
rules: {
'playwright/no-networkidle': 'off',
'playwright/no-wait-for-timeout': 'off',
'playwright/expect-expect': 'error',
'playwright/no-skipped-test': 'off',
// 'imported/no-unused-import': 'off',
// 'imported/prefer-default-export': 'off',
// 'imported/no-default-export': 'off',
// 'imported/no-unresolved': 'error',
},
},
{
ignores: ['node_modules/', '/playwright/.cache/', '/playwright-report/', 'src/memfs/assets/*', '/test-results/'],
},
]