it('should support URL instances', async function() { const { server } = this.polly; server.any(this.recordUrl()).intercept((_, res) => res.sendStatus(200)); const res = await this.fetch(new URL(this.recordUrl())); expect(res.status).to.equal(200); });
it('.hasHeader()', function() { const { headers } = base; base.setHeader('One', '1'); expect(headers).to.deep.equal({ one: '1' }); expect(base.hasHeader('One')).to.be.true; expect(base.hasHeader('one')).to.be.true; expect(base.hasHeader('Two')).to.be.false; base.removeHeader('One'); expect(base.hasHeader('One')).to.be.false; expect(base.hasHeader('one')).to.be.false; });
describe( 'wpcom.site.post.comment.update', function () { it( 'should update a post comment', function ( done ) { testing_comment.update( fixture.post_comment + '-updated', function ( err, data ) { if ( err ) throw err; assert.equal( 'number', typeof data.ID ); assert.equal( 'object', typeof data.post ); assert.ok( data.post instanceof Object ); assert.equal( testing_comment._cid, data.ID ); done(); } ); } ); } );
it('can be scoped to multiple namespaces', function() { server.namespace('/api', () => { server.get('/foo').intercept(() => 'foo'); server.namespace('/v2', () => { server.get('/bar').intercept(() => 'bar'); }); }); expect(request('GET', '/api/foo')).to.equal('foo'); expect(request('GET', '/api/v2/bar')).to.equal('bar'); });
describe('hslToRgb', () => { it('should convert hsl to rgb', () => { const rgb = hslToRgb(214, 1, 0.5); expect(rgb).to.deep.equal([0, 110, 255]); }); });
it('should handle dynamic segments', function() { server.get('/foo/:seg1').intercept(() => 200); server.get('/foo/:seg1/bar/:seg2').intercept(() => 400); expect(request('GET', '/foo/42')).to.equal(200); expect(request('GET', '/foo/super-secret-guid')).to.equal(200); expect(request('GET', '/foo/42/bar/abc')).to.equal(400); });
it('should intercept', async function() { const { server } = this.polly; server.any(this.recordUrl()).intercept((_, res) => res.status(201)); server.get(this.recordUrl()).intercept((req, res) => res.json(req.query)); const res = await this.fetch(`${this.recordUrl()}?foo=bar`); const json = await res.json(); expect(res.status).to.equal(201); expect(json).to.deep.equal({ foo: 'bar' }); });
it('.getHeader()', function() { const { headers } = base; base.setHeader('One', '1'); expect(headers).to.deep.equal({ one: '1' }); expect(base.getHeader('One')).to.equal('1'); expect(base.getHeader('one')).to.equal('1'); expect(base.getHeader('Two')).to.be.undefined; base.removeHeader('One'); expect(base.getHeader('One')).to.be.undefined; expect(base.getHeader('one')).to.be.undefined; });
describe( 'wpcom.site.post.comments', function () { it( 'should get the post comments list', function ( done ) { testing_post.comments( function ( err, data ) { if ( err ) throw err; assert.equal( 'number', typeof data.found ); assert.equal( 'object', typeof data.comments ); assert.ok( data.comments instanceof Array ); done(); } ); } ); } );
describe('fahrenheitToCelsius', () => { it('should convert fahrenheit to celsius', () => { const celsius = fahrenheitToCelsius(68); expect(celsius).to.equal(20); }); });
it('should return status text', async function() { const { server } = this.polly; server.any(this.recordUrl()).intercept((_, res) => res.sendStatus(200)); const res = await this.fetch(new Request(this.recordUrl())); expect(res.statusText).to.equal('OK'); });