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

Add chai-setup script to consistently import additional matchers #537

Merged
merged 1 commit into from
Feb 14, 2024

Conversation

jordaniza
Copy link
Contributor

@jordaniza jordaniza commented Feb 13, 2024

Description

Chai requires binding matchers to the global test runner inside hardhat, not doing so leaves certain tests in the PSP to throw due to the matchers not being found.

The fix is to use

chai.use(smock.matchers);

But rather than write in every test file, we should define a setup script:

/**
 * Enable additional matchers for chai and smock
 * import this file in place of chai, i.e:
 * import {expect} from './chai-setup';
 **/
import {smock} from '@defi-wonderland/smock';
import chai from 'chai';

chai.use(smock.matchers);
export = chai;

Which can then be imported in place of Chai, in a consistent manner for all files.

import {expect} from './chai-setup'

Note: in theory there is a require field in the mocha config in hardhat. This doesn’t appear to actually run any scripts before the tests fire. Hardhat also exposes fixtures which could be an alternative approach, but since this is a global environment setup, it seems an import script is fine.

Task ID: OS-1041

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have selected the correct base branch.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.
  • I ran all tests with success and extended them if necessary.
  • I have updated the CHANGELOG.md file in the root folder.
  • I have updated the DEPLOYMENT_CHECKLIST file in the root folder.
  • I have updated the UPDATE_CHECKLIST file in the root folder.

Copy link
Contributor

@Rekard0 Rekard0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Rekard0 Rekard0 merged commit 8834c37 into develop Feb 14, 2024
25 checks passed
@Rekard0 Rekard0 deleted the fix/chai-matchers branch February 14, 2024 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants