Google Groups

ShouldContains not throwing if no element found

Andrew Smith Apr 26, 2012 6:45 AM
Posted in group: Nancy Web Framework

I have a unit test which looks something like the following:

BrowserResponse response = Browser.Post("/forgotpassword", with =>
with.FormValue("email", "");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
response.Body["#alert-error"].ShouldContain("Sorry, can't find that email address");  // <<< This doesn't throw

I was trying to get a failing test first so I just returned status code 200, expecting that the ShouldContain line would throw. But it doesn't, because there is no #alert-error element. Is this expected behaviour? I would've thought it should throw.

Happy to send a pull request, just want to be sure it wouldn't break things first