-
Notifications
You must be signed in to change notification settings - Fork 3
/
filter-spec.js
54 lines (47 loc) · 1.66 KB
/
filter-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/// <reference types="cypress" />
import { mount } from '../..'
import angular from 'angular'
import '../src/reverse'
/* eslint-env mocha */
describe('Filter', () => {
const getFilter$ = () => angular.injector(['ng']).get('$filter')
it('returns $filter', () => {
const $filter = getFilter$()
expect($filter).to.be.a('function')
})
it('returns built-in lowercase filter', () => {
const lowercase = getFilter$()('lowercase')
expect(lowercase).to.be.a('function')
expect(lowercase('FOOBar')).to.equal('foobar')
})
it('has user filter', () => {
// we don't even need to mount module "myReverseFilterApp"
// to get back the reverse filter
const $filter = angular
.injector(['ng', 'myReverseFilterApp'])
.get('$filter')
const reverse = $filter('reverse')
expect(reverse).to.be.a('function')
expect(reverse('foo-')).to.equal('-oof')
expect(reverse('foo-', true)).to.equal('-OOF')
// but we can mount template to see it in action
const template = `<div ng-controller="MyController">
<input ng-model="greeting" type="text"><br>
No filter: {{greeting}}<br>
Reverse: {{greeting|reverse}}<br>
Reverse + uppercase: {{greeting|reverse:true}}<br>
Reverse, filtered in controller: {{filteredGreeting}}<br>
</div>`
mount(template, ['myReverseFilterApp'])
cy.log('checking initial values')
cy.contains('div', 'Reverse: olleh')
cy.contains('div', 'Reverse + uppercase: OLLEH')
cy.log('changing values')
cy
.get('input')
.clear()
.type('Cypress')
cy.contains('div', 'Reverse: sserpyC')
cy.contains('div', 'Reverse + uppercase: SSERPYC')
})
})