mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 18:01:36 +03:00
fb044e6d88
refs #9389 - https://github.com/sinonjs/sinon/blob/master/CHANGELOG.md Breaking changes for Ghost: - no need to create a sandbox anymore, each file get's it's own sandbox - just require sinon and use this sandbox - you can still create separate sandboxes with .createSandbox - reset single stubs: use .resetHistory instead of .reset This is a global replace for any sandbox creation. --- From https://sinonjs.org/releases/v7.2.3/sandbox/ > Default sandbox > Since sinon@5.0.0, the sinon object is a default sandbox. Unless you have a very advanced setup or need a special configuration, you probably want to just use that one.
70 lines
1.8 KiB
JavaScript
70 lines
1.8 KiB
JavaScript
var should = require('should'),
|
|
sinon = require('sinon'),
|
|
helpers = require('../../../server/helpers'),
|
|
common = require('../../../server/lib/common');
|
|
|
|
describe('{{#is}} helper', function () {
|
|
afterEach(function () {
|
|
sinon.restore();
|
|
});
|
|
|
|
// All positive tests
|
|
it('should match single context "index"', function () {
|
|
var fn = sinon.spy(),
|
|
inverse = sinon.spy();
|
|
|
|
helpers.is.call(
|
|
{},
|
|
'index',
|
|
{fn: fn, inverse: inverse, data: {root: {context: ['home', 'index']}}}
|
|
);
|
|
|
|
fn.called.should.be.true();
|
|
inverse.called.should.be.false();
|
|
});
|
|
|
|
it('should match OR context "index, paged"', function () {
|
|
var fn = sinon.spy(),
|
|
inverse = sinon.spy();
|
|
|
|
helpers.is.call(
|
|
{},
|
|
'index, paged',
|
|
{fn: fn, inverse: inverse, data: {root: {context: ['tag', 'paged']}}}
|
|
);
|
|
|
|
fn.called.should.be.true();
|
|
inverse.called.should.be.false();
|
|
});
|
|
|
|
it('should not match "paged"', function () {
|
|
var fn = sinon.spy(),
|
|
inverse = sinon.spy();
|
|
|
|
helpers.is.call(
|
|
{},
|
|
'paged',
|
|
{fn: fn, inverse: inverse, data: {root: {context: ['index', 'home']}}}
|
|
);
|
|
|
|
fn.called.should.be.false();
|
|
inverse.called.should.be.true();
|
|
});
|
|
|
|
it('should log warning with no args', function () {
|
|
var fn = sinon.spy(),
|
|
inverse = sinon.spy(),
|
|
logWarn = sinon.stub(common.logging, 'warn');
|
|
|
|
helpers.is.call(
|
|
{},
|
|
undefined,
|
|
{fn: fn, inverse: inverse, data: {root: {context: ['index', 'home']}}}
|
|
);
|
|
|
|
logWarn.called.should.be.true();
|
|
fn.called.should.be.false();
|
|
inverse.called.should.be.false();
|
|
});
|
|
});
|