Иван Стрелков
describe('VideoView', () => {
it('is editable', () => {
expect(new VideoView().editable).toBe(true);
});
});
class VideoView extends GenericView {
editable = true;
// ...
}
Тестируются статические данные
describe('GenericView', () => {
it('disallows editing by default', () => {
var view = new GenericView();
expect(view.$el.find('.edit').length).toBe(0);
});
it('allows editing via specifying "editable" flag', () => {
var view = new GenericView({ editable: true });
expect(view.$el.find('.edit').length).toBe(1);
});
});
Применим в случае если editable - документированный флаг
describe('GenericView', () => {
it('disallows editing by default', () => {
var view = new GenericView();
expect(view.$el.find('.edit').length).toBe(0);
});
it('allows editing via specifying "editable" flag', () => {
var view = new GenericView({ editable: true });
expect(view.$el.find('.edit').length).toBe(1);
});
});
Применим в случае если editable - документированный флаг
describe('GenericView', () => {
it('disallows editing by default', () => {
var view = new GenericView();
expect(view.$el.find('.edit').length).toBe(0);
});
it('allows editing via specifying "editable" flag', () => {
var view = new GenericView({ editable: true });
expect(view.$el.find('.edit').length).toBe(1);
});
});
Применим в случае если editable - документированный флаг
describe('GenericView', () => {
it('disallows editing by default', () => {
var view = new GenericView();
expect(view.$el.find('.edit').length).toBe(0);
});
it('allows editing via specifying "editable" flag', () => {
var view = new GenericView({ editable: true });
expect(view.$el.find('.edit').length).toBe(1);
});
});
Применим в случае если editable - документированный флаг
describe('GenericView', () => {
it('disallows editing by default', () => {
var view = new GenericView();
expect(view.$el.find('.edit').length).toBe(0);
});
it('allows editing via specifying "editable" flag', () => {
var view = new GenericView({ editable: true });
expect(view.$el.find('.edit').length).toBe(1);
});
});
Применим в случае если editable - документированный флаг
describe('VideoView', () => {
describe('editing', () => {
beforeEach(() => {
this.view = new VideoView();
view.$el.find('.edit').click();
});
it('opens editing popup', () => {
expect(this.view.$el.find('.editing-popup').length).toBe(1);
});
it('saves on editing', () => {
this.view.$el.find('.title').val('new value').change();
this.view.$el.find('.save').click();
expect(this.view.model.get('title')).toBe('new value');
});
});
describe('VideoView', () => {
describe('editing', () => {
beforeEach(() => {
this.view = new VideoView();
view.$el.find('.edit').click();
});
it('opens editing popup', () => {
expect(this.view.$el.find('.editing-popup').length).toBe(1);
});
it('saves on editing', () => {
this.view.$el.find('.title').val('new value').change();
this.view.$el.find('.save').click();
expect(this.view.model.get('title')).toBe('new value');
});
});
describe('VideoView', () => {
describe('editing', () => {
beforeEach(() => {
this.view = new VideoView();
view.$el.find('.edit').click();
});
it('opens editing popup', () => {
expect(this.view.$el.find('.editing-popup').length).toBe(1);
});
it('saves on editing', () => {
this.view.$el.find('.title').val('new value').change();
this.view.$el.find('.save').click();
expect(this.view.model.get('title')).toBe('new value');
});
});
describe('VideoView', () => {
describe('editing', () => {
beforeEach(() => {
this.view = new VideoView();
view.$el.find('.edit').click();
});
it('opens editing popup', () => {
expect(this.view.$el.find('.editing-popup').length).toBe(1);
});
it('saves on editing', () => {
this.view.$el.find('.title').val('new value').change();
this.view.$el.find('.save').click();
expect(this.view.model.get('title')).toBe('new value');
});
});
describe('VideoView', () => {
describe('editing', () => {
beforeEach(() => {
this.view = new VideoView();
view.$el.find('.edit').click();
});
it('opens editing popup', () => {
expect(this.view.$el.find('.editing-popup').length).toBe(1);
});
it('saves on editing', () => {
this.view.$el.find('.title').val('new value').change();
this.view.$el.find('.save').click();
expect(this.view.model.get('title')).toBe('new value');
});
});
describe('VideoView', () => {
describe('editing', () => {
beforeEach(() => {
this.view = new VideoView();
view.$el.find('.edit').click();
});
it('opens editing popup', () => {
expect(this.view.$el.find('.editing-popup').length).toBe(1);
});
it('saves on editing', () => {
this.view.$el.find('.title').val('new value').change();
this.view.$el.find('.save').click();
expect(this.view.model.get('title')).toBe('new value');
});
});
describe('VideoView', () => {
describe('editing', () => {
beforeEach(() => {
this.view = new VideoView();
view.$el.find('.edit').click();
});
it('opens editing popup', () => {
expect(this.view.$el.find('.editing-popup').length).toBe(1);
});
it('saves on editing', () => {
this.view.$el.find('.title').val('new value').change();
this.view.$el.find('.save').click();
expect(this.view.model.get('title')).toBe('new value');
});
});
it('performs ajax call to /rest/images', () => {
sinon.stub(jQuery, 'ajax');
fetchImages();
assert(jQuery.ajax.calledWith('/rest/images'));
});
module.exports = {
build() {
firstLib.clean('build')
.then(() => secondLib.compileJS('src', 'build'))
.then(() => thirdLib.optimizeCSS())
}
};
module.exports = {
build() {
firstLib.clean('build') // очистка
.then(() => secondLib.compileJS('src', 'build'))
.then(() => thirdLib.optimizeCSS());
}
};
module.exports = {
build() {
firstLib.clean('build')
.then(() => secondLib.compileJS('src', 'build')) // JS
.then(() => thirdLib.optimizeCSS());
}
};
module.exports = {
build() {
firstLib.clean('build')
.then(() => secondLib.compileJS('src', 'build'))
.then(() => thirdLib.optimizeCSS()); // CSS
}
};
describe('build step', () => {
beforeEach(() => {
// Подменяем библиотечные методы моками с resolved promises
buildSystem.build();
});
it('builds, compiles and does something else', () => {
assert(firstLib.clean.calledWith('build'));
assert(secondLib.compileJS.calledWith('src', 'build'));
assert(thirdLib.optimizeCSS.called);
});
});
describe('build step', () => {
beforeEach(() => {
// Подменяем библиотечные методы моками с resolved promises
buildSystem.build();
});
it('builds, compiles and does something else', () => {
assert(firstLib.clean.calledWith('build'));
assert(secondLib.compileJS.calledWith('src', 'build'));
assert(thirdLib.optimizeCSS.called);
});
});
describe('build step', () => {
beforeEach(() => {
// Подменяем библиотечные методы моками с resolved promises
buildSystem.build();
});
it('builds, compiles and does something else', () => {
assert(firstLib.clean.calledWith('build'));
assert(secondLib.compileJS.calledWith('src', 'build'));
assert(thirdLib.optimizeCSS.called);
});
});
describe('build step', () => {
beforeEach(() => {
// Подменяем библиотечные методы моками с resolved promises
buildSystem.build();
});
it('builds, compiles and does something else', () => {
assert(firstLib.clean.calledWith('build')); // очистка
assert(secondLib.compileJS.calledWith('src', 'build'));
assert(thirdLib.optimizeCSS.called);
});
});
describe('build step', () => {
beforeEach(() => {
// Подменяем библиотечные методы моками с resolved promises
buildSystem.build();
});
it('builds, compiles and does something else', () => {
assert(firstLib.clean.calledWith('build'));
assert(secondLib.compileJS.calledWith('src', 'build')); // JS
assert(thirdLib.optimizeCSS.called);
});
});
describe('build step', () => {
beforeEach(() => {
// Подменяем библиотечные методы моками с resolved promises
buildSystem.build();
});
it('builds, compiles and does something else', () => {
assert(firstLib.clean.calledWith('build'));
assert(secondLib.compileJS.calledWith('src', 'build'));
assert(thirdLib.optimizeCSS.called); // CSS
});
});
class HomePage extends React.Component {
render() {
return (
<div>
<Header userName={this.props.userName} />
<Content> {this.props.invitation} </Content>
<Footer showSocial />
</div>
)
}
}
class HomePage extends React.Component {
render() {
return (
<div>
<Header userName={this.props.userName} />
<Content> {this.props.invitation} </Content>
<Footer showSocial />
</div>
)
}
}
class HomePage extends React.Component {
render() {
return (
<div>
<Header userName={this.props.userName} />
<Content> {this.props.invitation} </Content>
<Footer showSocial />
</div>
)
}
}
class HomePage extends React.Component {
render() {
return (
<div>
<Header userName={this.props.userName} />
<Content> {this.props.invitation} </Content>
<Footer showSocial />
</div>
)
}
}
describe('HomePage', () => {
beforeEach(() => { /* <HomePage userName="vasya" invitation="hello"/> */ });
it('renders header with userName', () => {
let header = TestUtils.findRenderedComponent(this.homePage, Header);
expect(header.props.userName).toBe('vasya');
});
it('renders footer', () => {
let footer = TestUtils.findRenderedComponent(this.homePage, Footer);
expect(footer.props.showSocial).toBe(true);
});
it('renders invitation', () => {
expect(this.container.innerHTML).toContain('hello');
});
});
describe('HomePage', () => {
beforeEach(() => { /* <HomePage userName="vasya" invitation="hello"/> */ });
it('renders header with userName', () => {
let header = TestUtils.findRenderedComponent(this.homePage, Header);
expect(header.props.userName).toBe('vasya');
});
it('renders footer', () => {
let footer = TestUtils.findRenderedComponent(this.homePage, Footer);
expect(footer.props.showSocial).toBe(true);
});
it('renders invitation', () => {
expect(this.container.innerHTML).toContain('hello');
});
});
describe('HomePage', () => {
beforeEach(() => { /* <HomePage userName="vasya" invitation="hello"/> */ });
it('renders header with userName', () => {
let header = TestUtils.findRenderedComponent(this.homePage, Header);
expect(header.props.userName).toBe('vasya');
});
it('renders footer', () => {
let footer = TestUtils.findRenderedComponent(this.homePage, Footer);
expect(footer.props.showSocial).toBe(true);
});
it('renders invitation', () => {
expect(this.container.innerHTML).toContain('hello');
});
});
describe('HomePage', () => {
beforeEach(() => { /* <HomePage userName="vasya" invitation="hello"/> */ });
it('renders header with userName', () => {
let header = TestUtils.findRenderedComponent(this.homePage, Header);
expect(header.props.userName).toBe('vasya');
});
it('renders footer', () => {
let footer = TestUtils.findRenderedComponent(this.homePage, Footer);
expect(footer.props.showSocial).toBe(true);
});
it('renders invitation', () => {
expect(this.container.innerHTML).toContain('hello');
});
});
class HomePage extends React.Component {
render() {
return (
<div>
<Header userName={this.props.userName} />
<Content children={this.props.invitation} />
<Footer showSocial />
</div>
)
}
}
describe('HomePage', () => {
beforeEach(() => { /* <HomePage userName="vasya" invitation="hello"/> */ });
it('renders social icons', () => {
let twitterIcon =
this.container.querySelector('a[href^="https://twitter.com"]');
expect(twitterIcon).not.toBe(null);
});
});
getter | setter | |
---|---|---|
React | comp.state.myProp | comp.setState({ myProp: 'new value' }) |
Angular | $scope.myProp | $scope.myProp = 'new value' |
Knockout | viewModel.myProp() | viewModel.myProp('new value') |
Backbone | model.get('myProp') | model.set('myProp', 'new value') |
test() {
formPageObject.togglePartnersCheckbox();
formPageObject.avitoBalloon().hide();
formPageObject.toggleAvitoCheckbox();
assert(formPageObject.avitoBalloon().visible === false);
}
toggleAvitoCheckbox() {
this.avito().action.toggle.call(this.avito());
basis.asap.process();
}
class SearchForm extends React.Component {
constructor(props) {
this.handleChange =
_.debounce(this.handleChange.bind(this), 200);
}
renderInput() {
return <input ref="query" onChange={this.handleChange}/>;
}
handleChange() {
this.setState({ state: 'loading' });
fetchResults(this.refs.query.value).then(results => {
this.setState({ state: 'loaded', results });
});
}
}
class SearchForm extends React.Component {
constructor(props) {
this.handleChange =
_.debounce(this.handleChange.bind(this), 200);
}
renderInput() {
return <input ref="query" onChange={this.handleChange}/>;
}
handleChange() {
this.setState({ state: 'loading' });
fetchResults(this.refs.query.value).then(results => {
this.setState({ state: 'loaded', results });
});
}
}
class SearchForm extends React.Component {
constructor(props) {
this.handleChange =
_.debounce(this.handleChange.bind(this), 200);
}
renderInput() {
return <input ref="query" onChange={this.handleChange}/>;
}
handleChange() {
this.setState({ state: 'loading' });
fetchResults(this.refs.query.value).then(results => {
this.setState({ state: 'loaded', results });
});
}
}
class SearchForm extends React.Component {
constructor(props) {
this.handleChange =
_.debounce(this.handleChange.bind(this), 200);
}
renderInput() {
return <input ref="query" onChange={this.handleChange}/>;
}
handleChange() {
this.setState({ state: 'loading' });
fetchResults(this.refs.query.value).then(results => {
this.setState({ state: 'loaded', results });
});
}
}
class SearchForm extends React.Component {
constructor(props) {
this.handleChange =
_.debounce(this.handleChange.bind(this), 200);
}
renderInput() {
return <input ref="query" onChange={this.handleChange}/>;
}
handleChange() {
this.setState({ state: 'loading' });
fetchResults(this.refs.query.value).then(results => {
this.setState({ state: 'loaded', results });
});
}
}
class SearchForm extends React.Component {
constructor(props) {
this.handleChange =
_.debounce(this.handleChange.bind(this), 200);
}
renderInput() {
return <input ref="query" onChange={this.handleChange}/>;
}
handleChange() {
this.setState({ state: 'loading' });
fetchResults(this.refs.query.value).then(results => {
this.setState({ state: 'loaded', results });
});
}
}
class SearchForm extends React.Component {
constructor(props) {
this.debouncedHandleChange =
_.debounce(this.handleChange.bind(this), 200);
}
renderInput() {
return <input ref="query" onChange={this.debouncedHandleChange}/>;
}
handleChange() {
this.setState({ state: 'loading' });
fetchResults(this.refs.query.value).then(results => {
this.setState({ state: 'loaded', results });
});
}
}