Playwright-Util.t 892 B

1234567891011121314151617181920212223242526
  1. use Test2::V0 -target => 'Playwright::Util';
  2. use Test2::Tools::Explain;
  3. use Playwright::Util;
  4. use Test::MockModule qw{strict};
  5. my $lwpmock = Test::MockModule->new('LWP::UserAgent');
  6. $lwpmock->redefine('request', sub {
  7. return bless({},'BogusResponse');
  8. });
  9. no warnings qw{redefine once};
  10. my $json = '{ "error":true, "message":"waa"}';
  11. local *BogusResponse::decoded_content = sub {
  12. return $json;
  13. };
  14. use warnings;
  15. like( dies { Playwright::Util::request('tickle','chase',666, LWP::UserAgent->new(), a => 'b' ) }, qr/waa/i, "Bad response from server = BOOM");
  16. $json = '{ "error":false, "message": { "_type":"Bogus", "_guid":"abc123" } }';
  17. is(Playwright::Util::request('tickle','chase',666, LWP::UserAgent->new(), a => 'b' ), { _type => 'Bogus', _guid => 'abc123' }, "Good response from server decoded and returned");
  18. #Not testing async/await, mocking forks is bogus
  19. done_testing();