Chai as Promised:`rejectWith`用于特定的错误消息

时间:2016-11-23 01:53:51

标签: chai-as-promised

我有一个可以返回一些可能被拒绝的承诺的函数:

function get_post_siblings( $limit = 3, $date = '' ) {
global $wpdb, $post;

if( empty( $date ) )
    $date = $post->post_date;

//$date = '2009-06-20 12:00:00'; // test data

$limit = absint( $limit );
if( !$limit )
    return;

$p = $wpdb->get_results( "
(
    SELECT 
        p1.post_title, 
        p1.post_date,
        p1.post_name,
        p1.ID
    FROM 
        $wpdb->posts p1 
    WHERE 
        p1.post_date < '$date' AND 
        p1.post_type = 'work' AND 
        p1.post_status = 'publish' 
    ORDER by 
        p1.post_date DESC
    LIMIT 
        $limit
)
UNION 
(
    SELECT 
        p2.post_title, 
        p2.post_date,
        p2.post_name,
        p2.ID 
    FROM 
        $wpdb->posts p2 
    WHERE 
        p2.post_date > '$date' AND 
        p2.post_type = 'work' AND 
        p2.post_status = 'publish' 
    ORDER by
        p2.post_date DESC
    LIMIT 
        $limit
) 
ORDER by post_date DESC
" );
$i = 0;
$adjacents = array();
for( $c = count($p); $i < $c; $i++ )
    if( $i < $limit )
        $adjacents['prev'][] = $p[$i];
    else
        $adjacents['next'][] = $p[$i];

return $adjacents;

如果返回特定的拒绝消息,我希望Chai as Promised只传递此测试:

Promise.reject({ a : 'x' })
//  or
Promise.reject({ b : 'y' })
// etc.

我发现

之间没有区别
Promise.should.be.rejectedWith({ a : 'x'})

fooPromise.should.be.rejectedWith({ a : 'x'})

任何拒绝都将满足这些fooPromise.should.be.rejectedWith({ foo : 'bar'}) 测试。

是否有办法指定拒绝主体,以便只有在被测试的被拒绝承诺中返回该主体时,测试才会通过?我正在使用Chai-as-promised 6.0.0 谢谢

0 个答案:

没有答案