Usul al-Kafi
Book 4:
The Book of Divine Proof
Chapter 57
Transfer of knowledge
409. 3. Imam Jafar as-Sadiq (p): An Imam learns of his Imamate and completion of the command to him at the last moment of life of the preceding Imam.