Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

Expecting ContentType.json from server in Dart testing

I'm testing a the ContentType header returned from a Dart server.

test('Return type is JSON', () async {
  final client = HttpClient();
  final url = Uri.parse('$baseUrl/api/v1/playlists');
  final request = await client.getUrl(url);
  final response = await request.close();

  final contentType = response.headers.contentType;
  expect(contentType, ContentType.json);
});

When I run that it fails:

Expected: _ContentType:<application/json; charset=utf-8>
  Actual: _ContentType:<application/json; charset=utf-8>

But if I convert them to strings it passes:

expect(contentType.toString(), ContentType.json.toString());

Why didn't the original pass?

question from:https://stackoverflow.com/questions/65557666/expecting-contenttype-json-from-server-in-dart-testing

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...