Last active
October 19, 2021 09:47
-
-
Save kossnocorp/21938b8e83b5dae1cff85206d019b75a to your computer and use it in GitHub Desktop.
Solve Jest/Cypress conflict when using with Testing Library by using these custom wrappers:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* The code is based on Gleb Bahmutov's [local-cypress](https://github.com/bahmutov/local-cypress). | |
*/ | |
/// <reference types="cypress" /> | |
/// <reference types="@testing-library/cypress" /> | |
const win = window as unknown as Window & { | |
assert: Chai.AssertStatic | |
expect: Chai.ExpectStatic | |
Cypress: Cypress.Cypress & EventEmitter | |
cy: Cypress.cy & EventEmitter | |
} | |
/** | |
* Object `cy` all Cypress API commands. | |
* @see https://on.cypress.io/api | |
* @example | |
* cy.get('button').click() | |
* cy.get('.result').contains('Expected text') | |
*/ | |
export const cy = win.cy | |
/** | |
* Holds bundled Cypress utilities and constants. | |
* @see https://on.cypress.io/api | |
* @example | |
* Cypress.config("pageLoadTimeout") // => 60000 | |
* Cypress.version // => "6.3.0" | |
* Cypress._ // => Lodash _ | |
*/ | |
export const Cypress = win.Cypress | |
/** | |
* Chai assertion | |
* @example expect('hello').to.equal('hello') | |
*/ | |
export const expect = win.expect | |
/** | |
* Chai assertion | |
*/ | |
export const assert = win.assert | |
// Mocha's globals as local variables | |
export const describe: Mocha.SuiteFunction = window.describe | |
export const context: Mocha.SuiteFunction = window.context | |
export const xdescribe: Mocha.PendingSuiteFunction = window.xdescribe | |
export const xcontext: Mocha.PendingSuiteFunction = window.xcontext | |
export const before: Mocha.HookFunction = window.before | |
export const beforeEach: Mocha.HookFunction = window.beforeEach | |
export const after: Mocha.HookFunction = window.after | |
export const afterEach: Mocha.HookFunction = window.afterEach | |
export const it: Mocha.TestFunction = window.it | |
export const test: Mocha.TestFunction = window.test | |
export const xit: Mocha.PendingTestFunction = window.xit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference types="@types/jest" /> | |
/// <reference types="@types/testing-library__jest-dom" /> | |
const gl = global as unknown as NodeJS.Global & { | |
beforeAll: jest.Lifecycle | |
beforeEach: jest.Lifecycle | |
afterAll: jest.Lifecycle | |
afterEach: jest.Lifecycle | |
describe: jest.Describe | |
fdescribe: jest.Describe | |
xdescribe: jest.Describe | |
it: jest.It | |
fit: jest.It | |
xit: jest.It | |
test: jest.It | |
xtest: jest.It | |
expect: jest.Expect | |
} | |
export const beforeAll = gl.beforeAll | |
export const beforeEach = gl.beforeEach | |
export const afterAll = gl.afterAll | |
export const afterEach = gl.afterEach | |
export const describe = gl.describe | |
export const fdescribe = gl.fdescribe | |
export const xdescribe = gl.xdescribe | |
export const it = gl.it | |
export const fit = gl.fit | |
export const xit = gl.xit | |
export const test = gl.test | |
export const xtest = gl.xtest | |
export const expect = gl.expect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment