Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
jest-environment-jsdom
Advanced tools
The jest-environment-jsdom package is a custom environment for Jest that allows you to simulate a browser-like environment using jsdom. This is useful for testing web applications without running them in an actual browser. It provides a simulated DOM API that you can interact with in your tests.
Simulating browser environment for testing
This feature allows you to simulate browser-like interactions such as clicking a button and then asserting the expected outcome, all within a Node.js environment.
test('simulates a click event', () => {
document.body.innerHTML = '<button id="button">Click me</button>';
const button = document.getElementById('button');
button.addEventListener('click', () => {
button.innerHTML = 'Clicked';
});
button.click();
expect(button.innerHTML).toBe('Clicked');
});
Testing DOM manipulation
You can test DOM manipulation by creating, modifying, and removing elements, and then asserting that these changes have taken place as expected.
test('adds a new div to the body', () => {
const div = document.createElement('div');
div.id = 'new-div';
document.body.appendChild(div);
expect(document.getElementById('new-div')).not.toBeNull();
});
Mocking global variables
The package allows you to mock global variables such as localStorage, which is useful for testing code that interacts with browser APIs that are not available in Node.js.
test('mocks a global variable', () => {
global.localStorage = {
getItem: jest.fn().mockReturnValue('mockValue')
};
expect(global.localStorage.getItem('key')).toBe('mockValue');
});
This package is similar to jest-environment-jsdom but is intended for testing Node.js applications. It does not simulate a browser environment and is therefore not suitable for testing browser-specific code.
Karma is a test runner that works with any framework and allows you to run tests in real browsers. Unlike jest-environment-jsdom, which simulates a browser environment, Karma actually runs tests in real browsers, which can be more accurate but also slower and more complex to set up.
This package integrates jsdom with Mocha, another testing framework. It provides similar functionality to jest-environment-jsdom but is designed to work with Mocha instead of Jest.
Enzyme is a testing utility for React that makes it easier to assert, manipulate, and traverse your React Components' output. It can be used in conjunction with jest-environment-jsdom to test React components in a simulated browser environment.
jest 17.0.0
expect.extend
.--expand
(or -e
) to show the full diff.scriptPreprocessor
with the new transform
option.jest.resetAllMocks
which replaces jest.clearAllMocks
.jest-environment-node
..babelrc
is now part of the transform cache key in babel-jest
.jest-haste-map
.--json
now includes information about individual tests inside a file.FAQs
Unknown package
The npm package jest-environment-jsdom receives a total of 6,250,380 weekly downloads. As such, jest-environment-jsdom popularity was classified as popular.
We found that jest-environment-jsdom demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.