Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use odottaa in Es6 project #414

Open
polaire801 opened this issue May 3, 2024 · 1 comment
Open

Unable to use odottaa in Es6 project #414

polaire801 opened this issue May 3, 2024 · 1 comment

Comments

@polaire801
Copy link

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/'],
  },
]
@elaichenkov
Copy link
Owner

Hi Chris,

Thank you for the well-described issue. Unfortunately, I was not able to reproduce the issue. However, I created a basic repository with a similar setup that you have. Feel free to clone and try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants