mediawiki-extensions-Popups/tests/node-qunit/experiments.test.js
Stephen Niedzielski 57762e0417 Hygiene: favor const
Bug: T165036
Change-Id: I17d374eaac6627ca6a8ba178862b2a9cff2538c0
2018-03-21 10:44:24 +00:00

40 lines
811 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.ok( getBucketStub.calledOnce );
assert.deepEqual(
getBucketStub.getCall( 0 ).args,
[
{
enabled: true,
name: 'foo',
buckets: {
'true': 0.2,
'false': 0.8 // 1 - 0.2
}
},
'barbaz'
]
);
// ---
getBucketStub.returns( 'true' );
assert.ok(
experiments.weightedBoolean( 'foo', 0.2, 'barbaz' ),
'It should return true if the bucket is "true".'
);
} );