Bart D. Ehrman, The New Testament: A Historical Introduction to the Early Christian Writings, sixth edition (Oxford University Press, 2016), 14.
It appears then that our New Testament emerged out of the conflicts among Christian groups, and that the dominance of the proto-orthodox position was what led to the development of the Christian canon as we have it today….This is not to say, however, that the canon of Scripture was firmly set by the end of the second century. Indeed, it is a striking fact of history that even though the Four Gospels were widely considered authoritative by proto-orthodox Christians then – along with Acts, most of the Pauline epistles, and several of the longer general epistles – the collection of our twenty-seven books was not finalized until much later. For throughout the second, third, and fourth centuries proto-orthodox Christians continued to debate the acceptability of some of the other books.