本文整理汇总了TypeScript中mocha-jsdom.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: jsdom
describe('LabelType', () => {
var $:JQueryStatic;
if (typeof window === 'undefined') {
jsdom();
}
before(() => {
$ = require('jquery');
});
describe('render', () => {
it('should render an empty label element', () => {
var $label:JQuery;
var labelType = new LabelType();
labelType.render();
$label = $(labelType.el);
assert.equal($label.length, 1);
assert.equal($label.text().trim(), '');
});
it('should render a label element with text', () => {
var $label:JQuery;
var labelType = new LabelType({
data: 'foo'
});
labelType.render();
$label = $(labelType.el);
assert.equal($label.length, 1);
assert.equal($label.text().trim(), 'foo');
});
});
describe('getData', () => {
it('should return the label text', () => {
var $label:JQuery;
var labelType = new LabelType({
data: 'foo'
});
labelType.render();
$label = $(labelType.el);
assert.equal(labelType.getData(), 'foo');
$label.text('shazaam');
assert.equal(labelType.getData(), 'shazaam');
labelType.setData('kablooey');
assert.equal(labelType.getData(), 'kablooey');
});
});
describe('setData', () => {
it('should set the label text', () => {
var $label:JQuery;
var labelType = new LabelType();
labelType.render();
labelType.setData('shazaam');
$label = $(labelType.el);
assert.equal($label.text(), 'shazaam');
});
});
});
示例2: TextType
describe('GroupType', () => {
var $:JQueryStatic;
if (typeof window === 'undefined') {
jsdom();
}
before(() => {
$ = require('jquery');
});
describe('render', () => {
it('should render an empty HTML div element', () => {
var groupType = new GroupType();
var $group:JQuery;
groupType.render();
$group = $(groupType.el);
assert.equal($group.prop('tagName').toLowerCase(), 'div', 'Expected div element to exist');
assert.equal($group.children().length, 0, 'Expected group to have no children');
});
it('should render child form types', () => {
var $group:JQuery, $inputs:JQuery;
var groupType = new GroupType({
children: [
new TextType({
name: 'fooInput',
data: 'foo'
}),
new TextType({
name: 'barInput',
data: 'bar'
})
]
});
$group = $(groupType.render().el);
$inputs = $group.find('input');
assert.equal($inputs.length, 2,
'Expected 2 child inputs to be rendered');
assert.equal($inputs.eq(0).attr('name'), 'fooInput');
assert.equal($inputs.eq(1).attr('name'), 'barInput');
assert.equal($inputs.eq(0).val(), 'foo');
assert.equal($inputs.eq(1).val(), 'bar');
});
});
describe('removeChild', () => {
it('should remove a child element from the dom', () => {
var child:TextType;
var groupType = new GroupType({
children: [
child = new TextType({
name: 'fooInput',
data: 'foo'
})
]
});
groupType.render();
assert.equal($(groupType.el).find(child.el).length, 1, 'Child should have a parent element (baseline)');
groupType.removeChild(child);
assert.equal($(groupType.el).find(child.el).length, 0, 'Child should not have a parent element');
});
it('should not complain if the GroupType is not rendered', () => {
var child:TextType;
var groupType = new GroupType({
children: [
child = new TextType({
name: 'fooInput',
data: 'foo'
})
]
});
groupType.removeChild(child);
});
it('should not complain if the child element was closed independently', () => {
var child:TextType;
var groupType = new GroupType({
children: [
child = new TextType({
name: 'fooInput',
data: 'foo'
})
]
});
//.........这里部分代码省略.........
示例3: jsdom
describe('MultiChoiceType', () => {
var $:JQueryStatic;
if (typeof window === 'undefined') {
jsdom();
}
before(() => {
$ = require('jquery');
ServiceContainer.HtmlEvents = require('../../Util/JQueryHtmlEvents');
});
describe('render', () => {
it('should create checkboxes for each choice', () => {
var $checkboxes:JQuery;
var multiChoiceType = new MultiChoiceType({
choices: {
us: 'United States',
ca: 'Canada'
}
});
multiChoiceType.render();
$checkboxes = $(multiChoiceType.el).find('input[type=checkbox]');
assert.equal($checkboxes.length, 2,
'Should have rendered 2 checkboxes');
assert.equal($checkboxes.filter('[value="us"]').length, 1);
assert.equal($checkboxes.filter('[value="ca"]').length, 1);
});
it('should set the name of the checkbox to the data value', () => {
var $checkboxes:JQuery;
var multiChoiceType = new MultiChoiceType({
choices: {
us: 'United States',
ca: 'Canada'
}
});
multiChoiceType.render();
$checkboxes = $(multiChoiceType.el).find('input[type=checkbox]');
assert.equal($checkboxes.filter('[name="us"]').length, 1);
assert.equal($checkboxes.filter('[name="ca"]').length, 1);
});
it('should render labels for each checkbox', () => {
var $checkboxes:JQuery, $scope:JQuery
var $usLabel:JQuery, $caLabel:JQuery;
var usCheckboxId:string, caCheckboxId:string;
var multiChoiceType = new MultiChoiceType({
choices: {
us: 'United States',
ca: 'Canada'
}
});
multiChoiceType.render();
$scope = $(multiChoiceType.el);
$checkboxes = $scope.find('input[type=checkbox]');
usCheckboxId = $checkboxes.filter('[value="us"]').attr('id');
caCheckboxId = $checkboxes.filter('[value="ca"]').attr('id');
$usLabel = $scope.find('label[for="' + usCheckboxId + '"]');
$caLabel = $scope.find('label[for="' + caCheckboxId + '"]');
assert.equal($usLabel.length, 1, 'Should have a label for the US checkbox');
assert.equal($caLabel.length, 1, 'Should have a label for the Canada checkbox');
assert.equal($usLabel.text().trim(), 'United States');
assert.equal($caLabel.text().trim(), 'Canada');
});
it('should select the options specified in `data`', () => {
var $checkboxes:JQuery, $scope:JQuery;
var multiChoiceType = new MultiChoiceType({
choices: {
us: 'United States',
ca: 'Canada',
fr: 'France'
},
data: ['us', 'fr']
});
multiChoiceType.render();
$scope = $(multiChoiceType.el);
$checkboxes = $scope.find('input[type=checkbox]');
assert($checkboxes.filter('[value="us"]').is(':checked'), 'Expected US checkbox to be checked');
assert(!$checkboxes.filter('[value="ca"]').is(':checked'), 'Expected CA checkbox not to be checked');
assert($checkboxes.filter('[value="fr"]').is(':checked'), 'Expected FR checkbox to be checked');
});
});
//.........这里部分代码省略.........
示例4: TextType
describe('FormType', () => {
var $:JQueryStatic;
if (typeof window === 'undefined') {
jsdom();
}
before(() => {
$ = require('jquery');
ServiceContainer.HtmlEvents = require('../../Util/JQueryHtmlEvents');
});
describe('render', () => {
it('should render an empty HTML form', () => {
var formType = new FormType();
var $form;
formType.render();
$form = $(formType.el);
assert.equal($form.prop('tagName').toLowerCase(), 'form', 'Expected form element to exist');
assert.equal($form.children().length, 0, 'Expected form to have no children');
});
it('should render child form types', () => {
var $form:JQuery, $inputs:JQuery;
var formType = new FormType({
children: [
new TextType({
name: 'fooInput',
data: 'foo'
}),
new TextType({
name: 'barInput',
data: 'bar'
})
]
});
$form = $(formType.render().el);
$inputs = $form.find('input');
assert.equal($inputs.length, 2,
'Expected 2 child inputs to be rendered');
assert.equal($inputs.eq(0).attr('name'), 'fooInput');
assert.equal($inputs.eq(1).attr('name'), 'barInput');
assert.equal($inputs.eq(0).val(), 'foo');
assert.equal($inputs.eq(1).val(), 'bar');
});
});
describe('`submit` event', () => {
it('should emit when you submit the form', () => {
var onSubmit = sinon.spy();
var $form:JQuery;
var formType = new FormType();
formType.render();
$form = $(formType.el);
$form.on('submit', (evt:JQueryEventObject) => {
onSubmit();
evt.preventDefault();
});
$form.submit();
assert(onSubmit.called, 'Expected onSubmit listener to have been called.');
});
});
describe('functional tests', () => {
it('should swap out child types', () => {
var $form:JQuery, $countrySelect:JQuery;
var usForm = new FormType({
name: 'usForm',
children: [
new ChoiceType({
name: 'sodaOrPop',
choices: {
'soda': 'It\' called soda',
'pop': 'No, it\'s caled pop.'
}
})
]
});
var franceForm = new FormType({
name: 'franceForm',
children: [
new ChoiceType({
name: 'croissantOrBaguette',
choices: {
'croissant': 'Croissant',
'baguette': 'Baguette'
//.........这里部分代码省略.........