mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
6f6c8f4521
refs #9178 - avoid importing 4 modules (logging, errors, events and i18n) - simply require common in each file
72 lines
1.9 KiB
JavaScript
72 lines
1.9 KiB
JavaScript
var should = require('should'), // jshint ignore:line
|
|
sinon = require('sinon'),
|
|
helpers = require('../../../server/helpers'),
|
|
common = require('../../../server/lib/common'),
|
|
|
|
sandbox = sinon.sandbox.create();
|
|
|
|
describe('{{#is}} helper', function () {
|
|
afterEach(function () {
|
|
sandbox.restore();
|
|
});
|
|
|
|
// All positive tests
|
|
it('should match single context "index"', function () {
|
|
var fn = sandbox.spy(),
|
|
inverse = sandbox.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 = sandbox.spy(),
|
|
inverse = sandbox.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 = sandbox.spy(),
|
|
inverse = sandbox.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 = sandbox.spy(),
|
|
inverse = sandbox.spy(),
|
|
logWarn = sandbox.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();
|
|
});
|
|
});
|