File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ import * as cv from "opencv4nodejs-prebuilt" ;
2+ import { mockPartial } from "sneer" ;
3+ import { findEdges } from "./find-edges.function" ;
4+
5+ describe ( "findEdges" , ( ) => {
6+ it ( "should convert an image to grayscale and run Canny edge detection" , async ( ) => {
7+ // GIVEN
8+ const grayImageMock = mockPartial < cv . Mat > ( {
9+ cannyAsync : jest . fn ( )
10+ } ) ;
11+ const inputImageMock = mockPartial < cv . Mat > ( {
12+ cvtColorAsync : jest . fn ( ( ) => Promise . resolve ( grayImageMock ) )
13+ } ) ;
14+
15+ // WHEN
16+ await findEdges ( inputImageMock ) ;
17+
18+ // THEN
19+ expect ( inputImageMock . cvtColorAsync ) . toBeCalledWith ( cv . COLOR_BGR2GRAY ) ;
20+ expect ( grayImageMock . cannyAsync ) . toBeCalledWith ( 50 , 200 ) ;
21+ } ) ;
22+ } ) ;
Original file line number Diff line number Diff line change 1+ import * as cv from "opencv4nodejs-prebuilt" ;
2+
3+ export const findEdges = async ( image : cv . Mat ) : Promise < cv . Mat > => {
4+ const gray = await image . cvtColorAsync ( cv . COLOR_BGR2GRAY ) ;
5+ return gray . cannyAsync ( 50 , 200 ) ;
6+ } ;
You can’t perform that action at this time.
0 commit comments