Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
qunit-decorators
Advanced tools
Readme
Allow QUnit tests to be written and organized with JavaScript or TypeScript decorators. Inspired by mocha-typescript.
npm install --save-dev qunit-decorators
or
yarn add -D qunit-decorators
When using qunit-decorators, you’ll use classes organize modules, and methods for your tests
import { suite, test } from 'qunit-decorators';
@suite // <-- decorate your modules with @suite
class UserLoginTests {
// ↓ decorate your test methods with @test
@test 'login without password should fail'(assert: Assert) {
let { result } = loginWithoutPassword(); // the thing being tested
assert.equal(result, 'ERROR', 'User receives an error'); // ✅
}
foo() {} // <-- You're free to put other non-test methods on the class too!
}
In the example above your test module would get its name from the class (UserLoginTests
), and it would contain a test that gets its name from the method (login without password should fail
). If you want to have a method name that's different from the name of the test, you can also pass an argument to these decorators.
see: QUnit.module and QUnit.test
import { suite, test } from 'qunit-decorators';
@suite('User authentication test suite')
class UserLoginTests {
@test('Missing password case errors as expected')
testMethod(assert: Assert) {
let { result } = loginWithoutPassword(); // the thing being tested
assert.equal(result, 'ERROR', 'User receives an error'); // ✅
}
}
Sometimes it's useful to temporarily focus on a subset of tests while writing new code. QUnit allows you to focus on a combination of modules and tests within modules.
see: QUnit.only
import { suite, test } from 'qunit-decorators';
@suite.only('Working on some new tests')
class MyNewTests { ... }
@suite
class ExistingFeatureTests {
@test.only 'Fixing something else too'() { ... }
}
Alternatively, you may choose specific tests or modules to skip in a similar way
see: QUnit.skip
import { suite, test } from 'qunit-decorators';
@suite.skip('Things that take a long time')
class SlowTests { ... }
@suite
class ExistingFeatureTests {
@test.skip 'a buggy test I am still working on'() { ... }
}
Particularly while in the middle of a code change, you'll sometimes have tests that won't pass because you haven't gotten to them yet. You may mark these tests with @test.todo
, and they'll pass as long as at least one assertion fails.
see: QUnit.todo
import { suite, test } from 'qunit-decorators';
@suite
class WIPBugFixes {
@test.todo 'We\'ll get to this Soon™️'(assert) {
assert.ok(false);
}
}
When defining a QUnit suite, you have an opportunity to set up one or more hooks to customize code that runs before or after your tests.
see: QUnit.module
There are a variety of ways you can provide functions for hooks, and qunit-decorators doesn't interfere with their normal capabilities and operation (i.e., if you return a promise from a hook, QUnit will wait for that promise to resolve before running other hooks or tests).
You may define hooks as member functions on the module's class
import { suite, test } from 'qunit-decorators';
import Pretender from 'pretender';
let server;
@suite('A better test module')
class BetterModule {
before() {
server = new Pretender();
}
after() {
server.shutdown();
}
beforeEach() { ... }
afterEach() { ... }
}
or pass the hooks passed into the @suite
decorator as an object
import { suite, test } from 'qunit-decorators';
import Pretender from 'pretender';
let server;
const myHooks = {
before() {
// Start intercepting XHR
server = new Pretender();
},
after() {
// Restore original XHR
server.shutdown();
}
}
@suite('A good test module', myHooks)
class GoodModule {
}
or pass in a callback that receives an object which may be used to register hooks
import { suite, test } from 'qunit-decorators';
import Pretender from 'pretender';
@suite('A better test module', hooks => {
let server;
hooks.before(() => {
server = new Pretender();
});
hooks.after(() => {
server.shutdown();
});
})
class BetterModule {
}
(c) 2018 LinkedIn
FAQs
QUnit tests in ES6 and TypeScript via decorators
The npm package qunit-decorators receives a total of 482 weekly downloads. As such, qunit-decorators popularity was classified as not popular.
We found that qunit-decorators demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.