it('spreads user props', () => { // JSX does not render custom html attributes so we prefix them with data-*. // https://facebook.github.io/react/docs/jsx-gotchas.html#custom-html-attributes const props = { [`data-${_.kebabCase(faker.hacker.noun())}`]: faker.hacker.verb(), } shallow(<Component {...requiredProps} {...props} />) .should.have.descendants(props) })
it('updates text when value changed', () => { const initialValue = faker.hacker.noun() const nextValue = faker.hacker.noun() wrapperMount(<Search results={options} minCharacters={0} value={initialValue} />) .find('.prompt') .should.have.value(initialValue) wrapper .setProps({ value: nextValue }) .find('.prompt') .should.have.value(nextValue) })
it('spreads user props', () => { // JSX does not render custom html attributes so we prefix them with data-*. // https://facebook.github.io/react/docs/jsx-gotchas.html#custom-html-attributes const props = { [`data-${_.kebabCase(faker.hacker.noun())}`]: faker.hacker.verb(), } // descendants() accepts an enzyme <selector> // props should be spread on some descendant // we find the descendant with spread props via a matching props object selector // we do not test Component for props, of course they exist as we are spreading them shallow(<Component {...requiredProps} {...props} />) .should.have.descendants(props) })
it('does not set state for non autoControlledProps', () => { consoleUtil.disableOnce() TestClass = createTestClass({ autoControlledProps: [], state: {} }) const wrapper = shallow(<TestClass />) wrapper .instance() .trySetState({ [faker.hacker.noun()]: faker.hacker.verb() }) wrapper .state() .should.be.empty() })
describe('shorthand', () => { const baseProps = { content: faker.hacker.phrase(), description: faker.hacker.phrase(), header: faker.hacker.phrase(), } it('renders content without wrapping ListContent', () => { const wrapper = shallow(<ListContent {...baseProps} />) wrapper.find('ListHeader').should.have.prop('content', baseProps.header) wrapper.find('ListDescription').should.have.prop('content', baseProps.description) wrapper.should.contain.text(baseProps.content) }) })
it('adds HeaderSubheader as child when there is an image', () => { const text = faker.hacker.phrase() shallow(<Header image='foo.png' subheader={text} />) .find('HeaderSubheader') .should.have.prop('content', text) })
it('is passed to Checkbox controls', () => { const text = faker.hacker.phrase() shallow(<FormField control={Checkbox} label={text} />) .find('Checkbox') .should.have.prop('label', text) })
it('wraps html radio inputs', () => { const text = faker.hacker.phrase() const label = shallow(<FormField control='input' label={text} type='radio' />).find('label') label.childAt(0).should.have.tagName('input') label.should.contain.text(text) })
it('sets the display text', () => { const text = faker.hacker.phrase() wrapperRender(<Dropdown {...requiredProps} text={text} />) .find('.text') .should.contain.text(text) })
it('called when click on center', () => { const spy = sandbox.spy() const wrapper = mount(<Dimmer onClickOutside={spy}>{faker.hacker.phrase()}</Dimmer>) wrapper.find('div.center').simulate('click') spy.should.have.been.calledOnce() })
it('called when click on Dimmer', () => { const spy = sandbox.spy() mount(<Dimmer onClickOutside={spy}>{faker.hacker.phrase()}</Dimmer>) .simulate('click') spy.should.have.been.calledOnce() })
it('omitted when click on children', () => { const spy = sandbox.spy() const wrapper = mount(<Dimmer onClickOutside={spy}><div>{faker.hacker.phrase()}</div></Dimmer>) wrapper.find('div.center').childAt(0).simulate('click') spy.should.have.been.callCount(0) })
export const implementsIconProp = (Component, requiredProps = {}) => { const iconName = faker.hacker.noun() const assertValid = (element) => { const wrapper = shallow(element) wrapper .should.have.descendants('Icon') wrapper .find('Icon') .should.have.prop('name', iconName) } describe('icon (common)', () => { _noDefaultClassNameFromProp(Component, 'icon') it('has no i when not defined', () => { shallow(<Component />) .should.not.have.descendants('i') }) it('accepts an Icon instance', () => { const icon = <Icon name={iconName} /> assertValid(<Component icon={icon} />) }) it('accepts an icon name string', () => { assertValid(<Component icon={iconName} />) }) }) }
describe('renders children', () => { const firstText = faker.hacker.phrase() const secondText = faker.hacker.phrase() it('with `items` prop', () => { const items = [ { header: firstText }, { header: secondText }, ] const wrapper = mount(<CardGroup items={items} />).find('Card') wrapper.first().find('CardHeader').should.contain.text(firstText) wrapper.last().find('CardHeader').should.contain.text(secondText) }) })
it('is passed to Radio controls', () => { const text = faker.hacker.phrase() shallow(<FormField control={Radio} label={text} />) .find('Radio') .should.have.prop('label', text) })
_.times(randInt(100, 150), function (i) { // random requests models.Request.create({ title: faker.hacker.phrase(), body: faker.lorem.paragraphs(randInt(1, 4)), offer: randRoundInt(100, 10000), createdAt: randDate() }).then(function (request) { myModels.requests.push(request); request.setUser(randFromObj(myModels.user)).then(function (model) { request.setTags(randTags(myModels.tags)).then(function (model) { request.setComments(randComments(myModels.comments)).then(function (model) { var proposals = randProposals(myModels.proposals); request.setProposals(proposals).then(function (model) { // give each proposal a user _.each(proposals, function (proposal) { randFromObj(myModels.user).addProposal(proposal); }); // 33% chance of accepting one proposal if (proposals.length && randInt(0, 100) % 3 === 0) { proposals[0].set('state', 1).save(); } }); }); }); }); }); });
exports.populate = function(opts, callback) { console.time('populateComments'); var c = opts.count; var count = (c && Number(c)) || DEFAULT_COMMENT_COUNT; console.info('populating ' + count + ' Comments...'); bar.init(count); var comments = []; for (var i=0; i<count; i++) { comments.push({ content: faker.hacker.phrase(), uid: faker.random.number({min:1, max:config.users}), pid: faker.random.number({min:1, max:config.posts}), ts: String.format("(NOW() - '{0} seconds'::INTERVAL)", faker.random.number({min:0, max:864000})) }); } async.eachSeries(comments, function(comment, next){ bar.tick(); create({db: opts.db, comment: comment}, next); }, function(err){ console.timeEnd('populateComments'); if (callback) callback(err); }); };
it('does not set state for props passed as null by the parent', () => { consoleUtil.disableOnce() const props = makeProps() const autoControlledProps = _.keys(props) const randomProp = _.sample(autoControlledProps) const randomValue = faker.hacker.phrase() props[randomProp] = null TestClass = createTestClass({ autoControlledProps, state: {} }) const wrapper = shallow(<TestClass {...props } />) wrapper .instance() .trySetState({ [randomProp]: randomValue }) // not updated wrapper .should.not.have.state(randomProp, randomValue) // is original value wrapper .should.have.state(randomProp, props[randomProp]) })
it('passes prop to StepContent', () => { const title = faker.hacker.phrase() shallow(<Step title={title} />) .find('StepContent') .should.have.prop('title', title) })
var interval = setInterval(function () { room.message(faker.hacker.phrase()); if (++i > repeats) { clearInterval(interval); room.leave(); } }, 10000);
it('passes prop to StepContent', () => { const description = faker.hacker.phrase() shallow(<Step description={description} />) .find('StepContent') .should.have.prop('description', description) })
it('sets the display text', () => { const text = faker.hacker.phrase() wrapperRender(<Dropdown options={options} selection text={text} />) .find('.text') .should.contain.text(text) })
const buildFolder = function buildFolder (foldersCollection, paentFolderId) { const doc = { name: faker.hacker.noun(), parent: paentFolderId, created: new Date().toString() } return foldersCollection.create(doc) }
module.exports.newStageComment = (stageId, userId, cb) => { StagesComments.create({ stageId: mongoose.Types.ObjectId(stageId), text: faker.hacker.phrase(), userId: mongoose.Types.ObjectId(userId) }) .then(() => cb()); };
module.exports.newQuestComment = (questId, userId, cb) => { QuestsComments.create({ questId: mongoose.Types.ObjectId(questId), text: faker.hacker.phrase(), userId: mongoose.Types.ObjectId(userId) }) .then(() => cb()); };
it('is sibling to text inputs', () => { const text = faker.hacker.phrase() const wrapper = shallow(<FormField control='input' label={text} type='text' />) wrapper.childAt(0).should.have.tagName('label') wrapper.childAt(0).should.contain.text(text) wrapper.childAt(1).should.have.tagName('input') })
it('does not add prop value to className', () => { // silence propType warnings consoleUtil.disableOnce() const value = faker.hacker.noun() shallow(createElement(Component, { ...requiredProps, [propKey]: value })) .should.not.have.className(value) })
it('... and updates the custom fields requested in \'_updateCustomFields\'', (done) => { var customField = faker.hacker.noun(); data.customField = customField; vm.updateFromData(data) .always(function() { assert.equal(vm.customField(), customField); done(); }); });
const buildFile = function buildFile (parentFolderId, filesColleciton) { const doc = { name: faker.hacker.noun(), folder: parentFolderId, created: new Date().toString(), url: faker.image.imageUrl() } return filesColleciton.create(doc) }
const categoryOptions = _.range(0, categoryLength).reduce((memo, index) => { const category = `${faker.hacker.noun()}-${index}` memo[category] = { name: category, results: getOptions(categoryResultsLength), } return memo }, {})