使用Sinon v5.0.10对React's (relatively) new API中的Context.Consumer进行存根时,我遇到了一些麻烦。即使在对上下文使用者进行存根之后,我仍然会在默认上下文中获取该值,而不是存根指定的值。
export const MyComponent = props => (
<MyContext.Consumer>
{myContext => myContext.condition && props.children}
</MyContext.Consumer>
);
it("renders its children when the condition is true", () => {
// arrange
const fakeConsumer = sandbox.stub(MyContext, "Consumer");
fakeConsumer.callsFake(props => props.children({ condition: true }));
// act
const sut = enzyme.render(<MyComponent>fake content</MyComponent>);
// assert
assert.equal(sut.text(), "fake content"); // AssertionError: expected '' to equal 'fake content'
});
AssertionError: expected '' to equal 'fake content'
use DateTime::Format::Strptime qw( );
my $format = DateTime::Format::Strptime->new(
pattern => '%FT%T.%6N',
time_zone => 'UTC', # Or 'local' or 'America/Toronto' or '-0500'
on_error => 'croak',
);
my $dt = $format->parse_datetime('2019-01-24T00:00:05.011719');
$dt->set_formatter($format); # Set default stringification format.
$dt->truncate( to => 'second' )->add( seconds => 1 ) if $dt->nanosecond;
$dt->truncate( to => 'minute' )->add( minutes => 1 ) if $dt->second;
$dt->add( minutes => 5 - ( $dt->minute % 5 ) ) if $dt->minute % 5;
say $dt; # 2019-01-24T00:05:00.000000