aft-web-services
Version:
Automated Functional Testing (AFT) module for testing web services over HTTP and HTTPS
40 lines (32 loc) • 1.04 kB
text/typescript
import { httpData, HttpResponse } from "../../src";
describe('HttpData', () => {
it('can deserialise JSON data to Typed JavaScript object', () => {
let response: HttpResponse = {
data: '{"bar":"sample", "baz":2}'
};
let foo: Foo = httpData.as<Foo>(response);
expect(foo).toBeDefined();
expect(foo.bar).toEqual('sample');
expect(foo.baz).toEqual(2);
});
it('can deserialise XML data to Document object', () => {
let response: HttpResponse = {
headers: {"content-type": "text/xml"},
data: '<foo><bar>sample</bar><baz>2</baz></foo>'
};
let yop: Yop = httpData.as<Yop>(response);
expect(yop).toBeDefined();
expect(yop.foo.bar.keyValue).toEqual('sample');
expect(yop.foo.baz.keyValue).toEqual(2);
});
});
type Foo = {
bar: string;
baz: number;
}
type Yop = {
foo: {
bar: {keyValue: string},
baz: {keyValue: number}
};
}