Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Sep 4, 2024
1 parent 9ce013e commit f5de2fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions web/lib/src/helpers/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ extension TouchListConvert on TouchList {
List<Touch> toList() => JSImmutableListWrapper<TouchList, Touch>(this);
}

/// Returns all response headers as a key-value map.
///
/// Multiple values for the same header key can be combined into one,
/// separated by a comma and a space.
///
/// See: http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader()-method
extension XMLHttpRequestGlue on XMLHttpRequest {
Map<String, String> get responseHeaders {
// from Closure's goog.net.Xhrio.getResponseHeaders.
Expand Down
18 changes: 18 additions & 0 deletions web/test/helpers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,22 @@ void main() {
// Ensure accessing any arbitrary item in the list does not throw.
expect(() => dartList[0], returnsNormally);
});

test('Headers to map', () async {
final request = XMLHttpRequest();
request.open('GET', 'www.google.com');
request.send();
await request.onLoad.first;

expect(
request.responseHeaders,
allOf(
containsPair('content-length', '10'),
containsPair('content-type', 'text/plain; charset=utf-8'),
containsPair('x-content-type-options', 'nosniff'),
containsPair('x-frame-options', 'SAMEORIGIN'),
containsPair('x-xss-protection', '1; mode=block'),
),
);
});
}

0 comments on commit f5de2fd

Please sign in to comment.