mediawiki-extensions-Popups/tests/node-qunit/experiments.test.js
Ed Sanders e1c4e94b23 build: Update eslint-config-wikimedia to 0.10.0
Also enable jquery ruleset.

Change-Id: Ie1f43d0335ea2aad1e2dd5d86b775316105c3d90
2019-01-31 11:05:33 +01:00

45 lines
916 B
JavaScript

import createExperiments from '../../src/experiments';
QUnit.module( 'ext.popups/experiments#weightedBoolean' );
QUnit.test( 'it should call mw.experiments#getBucket', function ( assert ) {
const getBucketStub = this.sandbox.stub(),
stubMWExperiments = {
getBucket: getBucketStub
},
experiments = createExperiments( stubMWExperiments );
experiments.weightedBoolean( 'foo', 0.2, 'barbaz' );
assert.strictEqual(
getBucketStub.callCount,
1,
'The bucketer was invoked once.'
);
assert.deepEqual(
getBucketStub.getCall( 0 ).args,
[
{
enabled: true,
name: 'foo',
buckets: {
true: 0.2,
false: 0.8 // 1 - 0.2
}
},
'barbaz'
],
'The bucketer was called with the correct arguments.'
);
// ---
getBucketStub.returns( 'true' );
assert.ok(
experiments.weightedBoolean( 'foo', 0.2, 'barbaz' ),
'It should return true if the bucket is "true".'
);
} );